Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: I am having problems setting a Cookie

by zengargoyle (Deacon)
on Sep 22, 2002 at 00:07 UTC ( [id://199822]=note: print w/replies, xml ) Need Help??


in reply to I am having problems setting a Cookie

What works for me I copied almost vebatum from CGI Programming with Perl.

#!/usr/bin/perl -T # # the main page. /cgi-bin/main.pl # use strict; use warnings; use CGI; my $q = new CGI; my $cookie = $q->cookie( -name => 'session_id' ) || set_and_test_cookie( $q ); # if you get here, you have a cookie # use cookie for whatever... exit; sub set_and_test_cookie { my $q = shift; my $server = $q->server_name; my $session_id = $ENV{UNIQUE_ID}; # change to taste my $cookie = $q->cookie( -name => 'session_id', -value => $session_id, -path => '/cgi-bin', -secure => 1, ); print $q->redirect( -url => "https://$server/cgi-bin/cookie_test.pl", -cookie => $cookie, ); exit; } # # end main.pl # #!/usr/bin/perl -T # # check the cookie. /cgi-bin/cookie_test.pl # use strict; use warnings; use CGI; use constant SOURCE_CGI => "/cgi-bin/main.pl"; my $q = new CGI; my $cookie = $q->cookie( -name => 'session_id' ); if ( defined $cookie ) { print $q->redirect( -url => SOURCE_CGI ); # ok, go back. } else { print $q->header( -type => 'text/html' ), $q->start_html( "Cookies Disabled" ), $q->h1( "Cookies Disabled" ), $q->p( "Your browser is not accepting cookies. You need them. Ena +ble them and ", $q->a( { -href => SOURCE_CGI }, "Try Again" ), '.' ), $q->end_html; } # end cookie_test.pl

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-25 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found