Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: CGI Session - Refresh Problem

by rhesa (Vicar)
on Apr 24, 2008 at 10:37 UTC ( [id://682600]=note: print w/replies, xml ) Need Help??


in reply to CGI Session - Refresh Problem

You only get one chance to print the HTTP headers, so your second print $cgi->header isn't going to be effective.

The solution is to first create/retrieve the session, then bake the cookie, and only then print the header:

#!/perl/bin/perl -wT use strict; use CGI; use CGI::Session; my $cgi = CGI->new; my $session = CGI::Session->new( undef, $cgi, {Directory=>'/tmp'} +); my $cookie = $cgi->cookie(CGISESSID => $session->id ); print $cgi->header(-cookie=>$cookie); print $cgi->start_html("query.cgi"); print "cookies is : $cookie <BR>" ; my $sid = $session->id(); print "<BR>sid = $sid <BR>"; print $cgi->end_html;

Replies are listed 'Best First'.
Re^2: CGI Session - Refresh Problem
by d0353101 (Novice) on Apr 25, 2008 at 05:32 UTC
    Dear Rhesa, Many thanks for making this correction !! It worked like wonder.

    It resolved one query but still same Old questions are there:
    1. I am having administrator privilleges. On which path cookies are being stored. Cookies are not being stored at "C:\Documents and Settings\Administrator\Cookies"

    2. ( I do NOT want to use cookie)
    If I press refresh button on browser for "query.cgi" it creates a new session. I want the same session after refresh button is pressed. ( I do NOT want to use cookie) Please help me to achieve this.
      Those questions are answered in the manual, as well as in the excellent tutorial.

      1. You set the directory where sessions are stored with the Dir parameter;
      2. Instead of printing $cgi->header(...), you can also use $session->header(). That contains the logic for whether you need a new cookie or not.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://682600]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found