why can#39;t I create cookies in Firefox?(为什么我不能在 Firefox 中创建 cookie?)
问题描述
我无法使用以下行创建 Firefox cookie:
I am not able to create a Firefox cookie with following line:
setcookie("TestCookie", $value, time()+3600, "/", "localhost");
有人知道为什么吗?
我已经检查了 FF 中的设置,它接受来自第 3 方的 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 cookie 了,但是根据 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.
要在本地主机上设置 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我不能在 Firefox 中创建 cookie?
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
