in reply to Re^3: CGI session problem.
in thread CGI session problem.

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 }

Replies are listed 'Best First'.
Re^5: CGI session problem.
by moritz (Cardinal) on Jul 29, 2008 at 11:21 UTC
    - do your script headers contain a correct cookie? >> How do i know that whether it is a correct cookie ?

    You have to be a bit familiar with HTTP. If you are not, start reading a bit about it. There's lots of material out there on the internet. (I think this step is the most likely to work) <blockqoute> If so, is it also stored on disk? >> I am not aware about the location of cookies.

    Then it's high time to become aware. You're storing stuff on your server, and don't know where? It's documented, you know. From CGI::Session::Driver::file:

    If you wish to specify a session directory, use the Directory option, which denotes location of the directory where session ids are to be kept. If Directory is not set, defaults to whatever File::Spec->tmpdir() returns. So all the three lines in the SYNOPSIS section of this manual produce the same result on a UNIX machine.
    And finally...
    Does the browser send the cookie correctly back to the server? >> How do i know that ?

    Wireshark. The user makes a request, the server responds and sets a session ID in the cookie. During the next request, the client should send the same session ID as the cookie. Check that.

    I'm sorry to tell you that debugging persistence problems actually requires you to understand what's going on, which means you have to learn stuff about the underlying mechanisms.