I am not able to create a Firefox cookie with following line:
setcookie("TestCookie", $value, time()+3600, "/", "localhost");
Does someone know why?
I have checked the settings in FF and it accepts cookies from 3rd parties and are deleted when they expire.
EDIT: I can create now with this line:
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('c开发者_如何学Goookiename', 'data', time()+60*60*24*365, '/', $domain, false);
but how do I delete it?
I tried with just switching the + to - but it didn't work.
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('cookiename', 'data', time()-60*60*24*365, '/', $domain, false);
It's been awhile since I worked with localhost cookies, but according to the comments in the PHP manual, 'localhost' is an invalid value for the domain parameter.
To set a cookie on localhost, use false
instead. Example:
setcookie("TestCookie", $value, time()+3600, "/", false);
See http://www.php.net/manual/en/function.setcookie.php#73107
精彩评论