开发者

why can't I create cookies in Firefox?

开发者 https://www.devze.com 2022-12-14 02:43 出处:网络
I am not able to create a Firefox cookie with following line: setcookie(\"TestCookie\", $value, time()+3600, \"/\", \"localhost\");

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

0

精彩评论

暂无评论...
验证码 换一张
取 消