Dear Monks,
This is a newbie cookie question. I have done a web search on this, but have not found anything. Any help would be appreciated.
I'm trying to set cookies from a CGI script, but they don't get set on the filesystem. Here are some important points:
And here is my code:C:\Apache2\cgi-bin>perl cookie_test.pl Set-Cookie: login=o21PmKkYHxpCVIrPGlqaXZWIMqyLv11vJhMGEFEtdmvNRfFXXySd +0zvZxOU7U8Cg; path=/ Date: Thu, 13 Mar 2008 17:21:28 GMT Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <h2>Cookie Page</h2> </body> </html>
Am I doing something wrong in the way that I set the cookie, or is this possibly an environmental or browser problem?#!c:/perl/bin/perl.exe use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; use warnings 'all'; my $query = CGI->new(); my $cookie = &make_cookie; print $query->header(-cookie => $cookie), $query->start_html, "<h2>Coo +kie Page</h2>", $query->end_html; ################################################## sub make_cookie { my $cookie_id = &make_random_64_id; my $cookie = cookie(-name => 'login', -value => $cookie_id, -path +=> '/'); # Expires when browser is closed return $cookie; } ################################################## # Make random cookie ID from 64 random alphanumeric characters. sub make_random_64_id { my $rand_id; my @alpha_nums = ('a'..'z', 'A'..'Z', '0'..'9'); for (1..64) { $rand_id .= $alpha_nums[int(rand(@alpha_nums))]; } return $rand_id; }
Update: I also just tried adding the following line:
127.0.0.1 www.mylocalhost.com
to the C:\WINDOWS\system32\drivers\etc\hosts file, and then used the following url:
http://www.mylocalhost.com/cgi-bin/cookie_test.pl
The script diplays in the browser fine, but still no cookie is created.
Another update...think I have the answer: I just tried using Firefox off my flash drive (we can't install it on our machines here), and the cookie gets created....so it seems like this may be an IE issue.
In reply to Cookie not being set... by memnoch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |