develooper Front page | perl.beginners | Postings from March 2002

Cookie question

Thread Previous
From:
Motherofperls
Date:
March 4, 2002 08:15
Subject:
Cookie question
Message ID:
135.a585d69.29b4f230@aol.com
Hi,
I have a javascript program that makes cookies from outside the cgi-bin.
I want to access those cookies from a perl file within the cgi-bin.
Cookies are a new subject to me and this is the code I've learned so far in 
making cookies.

#!/usr/bin/perl -w 
# ic_cookies - sample CGI script that uses a cookie 
use CGI qw(:standard); 
use CGI::Cookie; 
use strict; 

my $cookname = "favorite ice cream"; 
my $favorite = param("flavor"); 
my $tasty = cookie($cookname) || 'mint'; 

unless ($favorite) { 
print header(), start_html("Ice Cookies"), h1("Hello Ice Cream"), 
hr(), start_form(), 
p("Please select a flavor: ", textfield("flavor",$tasty)),submit(), 
end_form(), hr(); 
exit; 
} 

my $cookie = cookie( 
-NAME => $cookname, 
-VALUE => $favorite, 
-EXPIRES => "+2nd", 
); 

print header(-COOKIE => $cookie), 
start_html("Ice Cookies, #2"), 
h1("Hello Ice Cream"), 
p("You chose as your favorite flavor `$favorite'."); 

my%cookies = fetch CGI::Cookie; 

foreach (keys %cookies) { 

print "$cookies{$_}<br>"; 

} 

This code only picks up cookies from the directory it's called from. 
Should I add something to it?
    
    
    
    



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About