|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I'm programming using PERL with CGI. I've been trying to set cookies with the following script: -------------------------------------------------------- #!/usr/bin/perl use CGI; use DBI; $foo = new CGI; $cookie = $foo->cookie(-name=>'name', -value=>'Random Name', -name=>'city', -value=>'Random city', -name=>'team', -value=>'some team', -name=>'age', -value=>'old', -expires=>'+1h', -path=>'/'); print $foo->header(-cookie=>$cookie); print "<HTML>\n"; print "<HEAD>\n"; print "<TITLE>Testing Cookies</TITLE>\n"; print "</HEAD>\n"; print "<BODY>\n"; print "The file ran properly.. but do you have a cookie set? Click <A HREF=\"take_cookie.cgi\">HERE</A> to see if it worked.\n"; print "</BODY>\n"; print "</HTML>\n"; -------------------------------------------------------- Now, I must be doing SOMETHING wrong with that coding, because when I run the following script (which extracts and prints the cookies that are set) the only thing I get is "age=twenty". I've checked the cookies on my comp, and that is in fact all that has been set. -------------------------------------------------------- #!/usr/bin/perl use CGI; use DBI; $foo = new CGI; print $foo->header; print "<HTML>\n"; print "<HEAD>\n"; print "<TITLE>Cookie Extract Test</TITLE>\n"; print "</HEAD>\n"; print "<BODY>\n"; print "Here are all the cookies that were set earlier.\n"; print "<HR><PRE>\n"; $raw_cookie = $ENV{'HTTP_COOKIE'}; @cookies = split /;/, $raw_cookie; foreach $cookie (@cookies) { print $cookie, "\n"; } print "</PRE>\n"; print "<HR>\n"; print "</BODY>\n"; print "</HTML>\n"; -------------------------------------------------------- Any help/advice/info is much appreciated. Thanx in advance, Stenyj |
|
#2
|
|||
|
|||
|
I believe you need one of these
Code:
$cookie = $foo->cookie(-name=>'name',
-value=>'Random Name',
-expires=>'+1h',
-path=>'/');
for each cookie. ie, you'd have a $cookie_name, $cookie_age, $cookie_city, etc. Then Code:
print $foo->header(-cookie=>$cookie_name,
-cookie=>$cookie_age,
-cookie=>$cookie_city);
Just a suggestions. If all else fails, try saving one cookie like this: Code:
$cookie = $foo->cookie(-name=>'all_info',
-value=>"name|city|age",
-expires=>'+1h',
-path=>'/');
Then just split the all_info cookie at the pipes when you pull it back in. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Can't seem to get my CGI created cookies working right.... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|