Hi,
I am getting a strange problem with two cookie scripts I've written.
The first, cookie_maker.cgi, creates two cookies containing a user id and a security key:
#!/usr/bin/perl -w
use strict;
# creates cookies print "Set-Cookie:user=cbfb\n"; print "Set-Cookie:secid=1234\n";
# creates html header print "Content-type: text/html\n\n"; print "<html><head></head><body>";
# prints message print "<p>Created a cookie!</p>";
# prints html footer print "</body></html>";
The second, cookie_reader.cgi, reads the cookies in a browser:
#!/usr/bin/perl -w
# creates html header print "Content-type: text/html\n\n"; print "<html><head></head><body>\n";
# reads cookie data if ($ENV{'HTTP_COOKIE'}) { @cookies = split (/;/, $ENV{'HTTP_COOKIE'}); foreach $cookie (@cookies) { ($name, $value) = split (/=/, $cookie); print "<p>$name=$value</p>\n"; $crumbs{$name} = $value; }
# found cookies print "<p>Found some cookies.</p>\n"; print "<p>user = $crumbs{'user'}</p>\n"; print "<p>secid = $crumbs{'secid'}</p>\n";
# no cookies found } else { print "<p>No cookies found.</p>\n"; }
# creates html footer print "</body></html>\n";
The second script outputs the following (in most browsers, see below):
user=cbfb
secid=1234
Found some cookies.
user = cbfb
secid =
For some reason, looking at the page source, a space has been inserted before the name of the second cookie, secid, so $crumbs{'secid'} doesn't seem to return anything:
<html><head></head><body> <p>user=cbfb</p> <p> secid=1234</p> <p>Found some cookies.</p> <p>user = cbfb</p> <p>secid = </p>
</body></html>
To confuse me even more, if I look at the cookie in Mozilla cookie manager, it seems to be fine (ie has no leading space).
It does the same thing in Firefox, Epiphany, Lynx and Galeon. But interestingly in Konqueror it is 'user' that has the leading space instead!
BTW, I am using MDK Linux 10.1 with Perl 5.8.5 on Apache.
I am sure I am overlooking something obvious here, but no amount of fiddling has sorted it out. Hopefully someone with a better knowledge of Perl/CGI can point out what I'm doing wrong? If so, I look forward to hearing from you!
Kind regards, Chris
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>