Forum Moderators: coopster
I'm just getting into PHP and am writing a simple PHP script that uses cookies, but for some reason, my $_COOKIE variable is empty. That is, there are no key=>value mappings in it at all. "echo empty($_COOKIE);" prints out 1 and "print_r($_COOKIE)" prints out "Array ( )".
I imagine cookies must be working in some form or another because I'm running Wordpress and the admin features that require cookies are all functioning normally. Also, the variables_order parameter on my server contains "C".
I have one setcookie() call at the beginning of the document (only if the request method is POST), but other than that, I don't perform any cookie-related operations or touch the $_COOKIE array. Perhaps Wordpress is doing something to it?
Any help with this phenomenon would be appreciated. Thanks!
- Alex
setcookie(name, value, expire, path, domain);
Also, when you are tryig to print the cookie value, you need to specify the cookie by it's name -
echo $_COOKIE["cookiename"];
here is an example of setting a cookie with a lifetime of 1 hour, name of "MyCookie", containing the value "Cookie Value" and set in the root -
setcookie("MyCookie", "Cookie Value", time()+3600,"/");
echo $_COOKIE["MyCookie"];
In any case, your reply led to me to realize my mistake. Thanks!