为什么我无法在Firefox中创建Cookie? [英] why can't I create cookies in Firefox?
问题描述
我无法创建具有以下行的Firefox Cookie:
I am not able to create a Firefox cookie with following line:
setcookie("TestCookie", $value, time()+3600, "/", "localhost");
有人知道为什么吗?
已检查FF中的设置,并接受来自第三方的Cookie,并在过期时将其删除。
I have checked the settings in FF and it accepts cookies from 3rd parties and are deleted when they expire.
编辑:我现在可以使用此行:
I can create now with this line:
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('cookiename', 'data', time()+60*60*24*365, '/', $domain, false);
但是如何删除?
我尝试只切换+到 - 但它没有工作。
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);
推荐答案
自从我使用localhost cookies后,根据PHP手册中的注释,localhost是域参数的无效值。
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.
要在localhost上设置cookie,请使用 false
。示例:
To set a cookie on localhost, use false
instead. Example:
setcookie("TestCookie", $value, time()+3600, "/", false);
查看 http://www.php.net/manual/en/function.setcookie.php#73107
这篇关于为什么我无法在Firefox中创建Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!