beginning_php thread: Reading a cookie
Message #1 by "Frank Fitzgerald" <writelivelihood@m...> on Tue, 21 May 2002 18:38:32|
I am trying to have a cookie set by one page and read by another. I have successfully set the cookie on
the first page with this code:
$cookie_name = "Wally";
$cookie_value = "test string!";
$cookie_expire = time()+14400;
$cookie_domain = "localhost";
setcookie($cookie_name, $cookie_value, $cookie_expire, "/", $cookie_domain, 0);
And this code on the second page tells me that the cookie is set, but it will not display the cookie's name:
$cookie_name = getenv($_COOKIE);
<script language = "php">
print "There's a cookie on your computer, and its name is $cookie_name";
print "There is no cookie";
Can someone tell me how to get name to display?
Message #2 by "Nikolai Devereaux" <yomama@u...> on Tue, 21 May 2002 11:09:53 -0700|
> I am trying to have a cookie set by one page and read by another.
> I have successfully set the cookie on the first page with this code:
I doubt it... copying your code onto my machine helped me figure out what's
However, I didn't get any cookies set with your code.
helped prove that.
The users comments on the php manual page for set cookie
say that the cookie spec mandates using two dots in the domain parameter.
Since you were using "localhost", I suspected that it was the reason your
script was failing.
As soon as I replaced "localhost" with the empty string '', it worked fine.