in reply to CGI session problem.

In the code that you showed you never call $session->flush(), thus never writing it to disk. Try this as a first attempt.

Replies are listed 'Best First'.
Re^2: CGI session problem.
by d0353101 (Novice) on Jul 29, 2008 at 10:02 UTC
    I tried to put it after creating the session bu IT does not work :
    ########### -- Creating The session--################## my $session = CGI::Session->new( undef, $cgi, {Directory=>'/tmp'} ); $session->flush(); my $cookie = $cgi->cookie(CGISESSID => $session->id ); print $cgi->header(-cookie=>$cookie);
      Then you have to start debugging - do your script headers contain a correct cookie? If so, is it also stored on disk? Does the browser send the cookie correctly back to the server?

      And before you start debugging, delete the cookies in your browser and try again.

      For debugging it might be useful to print the cookie and session id information to a log file, and to use wireshark or a similar tool to monitor your HTTP traffic.

        Many many thanks for your inputs. But I feel awkward to say that still I am stuck :-(

        I have made a small project with much labour but could not attach session for it. I was using the user_id as hard coded. But Now I need the user_id which is logged in ..but feeling helopless in session mngt.

        Please see my responses :

        - do your script headers contain a correct cookie? >> How do i know that whether it is a correct cookie ?

        If so, is it also stored on disk? >> I am not aware about the location of cookies.

        Does the browser send the cookie correctly back to the server? >> How do i know that ?

        And before you start debugging, delete the cookies in your browser and try again. >> done For debugging it might be useful to print the cookie and session id information to a log file, and to use wireshark or a similar tool to monitor your HTTP traffic. >> I am trying it on my PC where apache is installed. so no issue abt HTTP Traffic.

        # complete code of Redirected Page after login.cgi ######

        #!/perl/bin/perl -wT use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use CGI::Session; use strict; use vivek::money_pm::money ; my $cgi = CGI->new; #print $cgi->header; ########### -- SPECIAL CODE FOR FIRST PAGE OF WEBSITE--############### +### # user_id is being passed from login.cgi my $login_user_id = $cgi->param('user_id'); ########### -- Creating The session--################## my $session = CGI::Session->new( undef, $cgi, {Directory=>'/tmp'} ); $session->flush(); my $cookie = $cgi->cookie(CGISESSID => $session->id ); print $cgi->header(-cookie=>$cookie); print $cgi->start_html("ADD CATEGORY"); print " sid = ", $session->id(); if ($login_user_id) { $session->param('user_id', $login_user_id) ; + } print "<BR> login_user_id = $login_user_id <BR>" ; my $user_id = $session->param('user_id'); print " us +er_id = $user_id <BR>" ; #$user_id = 'vivekjain'; ###### HTML TEMPLATE ############## print "<TABLE BORDER = 1 width = 600 cellpadding = 10> "; print "<TR > <TD colspan = 2 height = 60 width = 150 align = left> Mai +n Heading </TD></TR>" ; print "<TR > <TD height = 30 width = 175 > ll"; # Left men +u & user_left_menu () ; print "</TD> <TD valign = 'top'> MAIN PAGE" ; ############################################## print "<p class=\"heading\"> Add Payment Category Here </p> <BR>" ; ############################################## if(!$cgi->param('flag') ) { # hidden Variable & add_category_html (); } else { my $category_name = $cgi->param('category_name'); my $description = $cgi->param('description'); my $payment_category = qq { INSERT INTO PAYMENT_CATEGORY ( CAT +EGORY_NAME, CATEGORY_TYPE_ID, DESCRIPTION, SURITY_OF_RETURN, CREATE_D +ATE, IS_DELETED, USER_ID) values( '$category_name','$category_type_id +', '$description', '$surity_of_return', NOW(), 'N', '$user_id') } ; # & query_execute ($payment_category) ; print"</TD> </TR>" ; # HTML Template ends print"</TABLE>"; print $cgi->end_html(); 1; sub add_category_html { HTML CODE FOR ADDING CATEGORY }