I'm trying to write and read a cookie, though I've got lot of problems doing so. I've tried this script:
#!/usr/bin/perl
use CGI qw/:standard/;
use CGI::Cookie;
# Create new cookies and send them
$cookie1 = new CGI::Cookie(-name=>'ID',-value=>123456);
$cookie2 = new CGI::Cookie(-name=>'preferences',
-value=>{ font => Helvetica,
size => 12 }
);
print header(-cookie=>[$cookie1,$cookie2]);
# fetch existing cookies
%cookies = fetch CGI::Cookie;
$id = $cookies{'ID'}->value;
print "..$id..";
And it gave this result:
Set-Cookie: ID=123456; path=/
Set-Cookie: preferences=font&Helvetica&size&12; path=/
Date: Mon, 01 Dec 2003 03:01:45 GMT
Content-Type: text/html; charset=ISO-8859-1
it seems like the cookie writing did take place, though it doesn't fetch the cookie again. I'm using Perlwiz to test this all and it gives me an error message:
Can't call method "value" on an undefined value at line 15
What can I do to make it run ?
#!/usr/bin/perl
use CGI qw/:standard/;
use CGI::Cookie;
# Create new cookies and send them
$cookie1 = new CGI::Cookie(-name=>'ID',-value=>123456);
$cookie2 = new CGI::Cookie(-name=>'preferences',
-value=>{ font => Helvetica,
size => 12 }
);
print header(-cookie=>[$cookie1,$cookie2]);
# fetch existing cookies
%cookies = fetch CGI::Cookie;
$id = $cookies{'ID'}->value;
print "..$id..";
And it gave this result:
Set-Cookie: ID=123456; path=/
Set-Cookie: preferences=font&Helvetica&size&12; path=/
Date: Mon, 01 Dec 2003 03:01:45 GMT
Content-Type: text/html; charset=ISO-8859-1
it seems like the cookie writing did take place, though it doesn't fetch the cookie again. I'm using Perlwiz to test this all and it gives me an error message:
Can't call method "value" on an undefined value at line 15
What can I do to make it run ?