[thelist] PHP help required please

Andrew Forsberg andrew at thepander.co.nz
Sun Feb 3 16:34:10 CST 2002

>just did the print_r... thing, all it produced was array(), and checking in
>my testing browser produced nothing - no cookie seems to have been set.
>however, when I set the cookie:
>setcookie("LOGININFO", "$username");
>I then, immediately afterwards, display the value by echo-ing it:
>echo "$LOGININFO";
>and this produces the right value.

Common Pitfalls:
* Cookies will not become visible until the next loading of a page
that the cookie should be visible for.

You can't read the cookie's current value from the page which sets
it. So, it's not reading $LOGININFO from a cookie, it's getting that
from some other part of your code -- your cookie variables and other
variables seem to be getting mixed up.

Try just putting the cookie setting code, the echo statement, and
print_r() / phpinfo() in an otherwise blank file, then loading it a
couple of times in your browser. If your browser shows up with a
cookie for your domain, or your choice of print_r or phpinfo shows
the $HTTP_COOKIE_VARS[] array with your variable set in it, then the
problem is elsewhere in your program.

setcookie("LOGININFO", "$username");
echo "<p>this is logininfo: $LOGININFO <br />";
echo "this is username: $username <br />";
echo "here are the variables stored in cookies on your machine: <br />";
print_r ($HTTP_COOKIE_VARS);
echo "<br /><br /><br /></p>";

 From memory, variables in PHP are set in the following order:

So perhaps your cookie variable is getting overridden by a get
variable? Just a guess.


Andrew Forsberg
uberNET - http://uber.net.nz/
the pander - http://thepander.co.nz/

More information about the thelist mailing list