Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie problems

Status
Not open for further replies.

Oostwijk

Technical User
Oct 19, 2003
82
NL
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 ?
 
Worked fine on my system. I cut and paste your code directly. On the first request ID does not exist. You may want to put a check around that.

if( exists($cookies{'ID'}) ) {
$id = $cookies{'ID'}->value;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top