Cookies.
I'm having a hell of a time with cookies. First of all, this is the correct way to set a cookie, right?
print "Set-Cookie:name=value; expires=Thu, 25-Nov-2000 00:00:00 GMT; secure\n";
Next, this is an acceptable way to grab cookies, right?
if ($ENV{'HTTP_COOKIE'}) {
@cookies = split (/;/, $ENV{'HTTP_COOKIE'});
foreach $cookie (@cookies) {
($name, $value) = split (/=/, $cookie);
$crumbs{$name} = $value;
}
}
OK, I have a script that just sets a cookie with a constant as the value and the name and has some pointless text. Now, when I visit a page on my server that gets the cookie and processes it, everything goes ok. Now, when I set the exact same cookie through a different script and go to the same page that got the cookie, the cookie doesn't show up. Any idea what's going on? I know, it's confusing, so please, ask questions.
richjb posted this at 04:01 — 14th August 2000.
They have: 193 posts
Joined: Feb 2000
:::Looking up info on cookies...:::
Just want to make sure, PERL, right?
Richard
richjb::369
richjb posted this at 04:18 — 14th August 2000.
They have: 193 posts
Joined: Feb 2000
Ok, the below code has been tested. I also did the scenerio you are in, one page sets, another reads. But this is both scripts in one:
#!/usr/bin/perl
BEGIN {
use CGI::Carp qw(fatalsToBrowser);
}
use CGI qw(param header cookie);
$packed_cookie = cookie( -NAME => "cookie name",
-VALUE => "this is the cookie data",
-EXPIRES => "+2y");
print header(-COOKIE => $packed_cookie);
$value = cookie("cookie name");
print "Done<br><br>Cookie value: $value";
Hope that helped. Post anyother problems you may get.
[edit]Forgot to uncomment a line in the code. :o[/edit]
Richard
richjb::370
[Edited by richjb on 08-14-2000 at 12:20 AM]
[email protected]
Everyone here has a website. It's just that not all are worth posting (Mine! ).
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.