setcookie()不会在Google Chrome中设置Cookie [英] setcookie() does not set cookie in Google Chrome
问题描述
我正在浏览一些关于如何设置cookie的PHP教程。我注意到,在FF4和IE9上成功设置了cookies,但是它并未在Chrome(11.0.696.60)中设置。 PHP文件是从XAMPP(localhost)提供的。
我试过w3schools的例子:
<?php
setcookie(user,Alex Porter,time()+ 3600);
?>
从本站(适用于localhost环境):
< ?php
setcookie(username,George,false,/,false);
?>
预先致谢。
为IP地址和 localhost
禁用cookie是设计决定。另请参阅: https://code.google.com/p/chromium/问题/详细信息?id = 56211
解决此问题的方法包括: 例如,在 PHP 中: 这里的值 注意:不设置域可防止cookie对子域可见。 I am going through some PHP tutorials on how to set cookies. I have noticed that cookies are successfully set on FF4 and IE9, however it does not get set in Chrome (11.0.696.60). The PHP file was served from XAMPP (localhost). I tried the example from w3schools: And from this site (for localhost environments): Thanks in advance. Disabling cookies for IP addresses and Ways to work around the issue include: For example, in PHP: Here the value Note: not setting the domain prevents the cookie being visible to sub-domains. 这篇关于setcookie()不会在Google Chrome中设置Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
/ etc / hosts
以使用 127.0.0.1 localhost.com
)。
setcookie(
$ AUTH_COOKIE_NAME,
$ cookie_value,
time()+ cookie_expiration(),
$ BASE_DIRECTORY,
null,
false,
true
);
null
表示域请勿设置。
<?php
setcookie("user", "Alex Porter", time()+3600);
?>
<?php
setcookie("username", "George", false, "/", false);
?>
localhost
was a design decision. See also: https://code.google.com/p/chromium/issues/detail?id=56211
/etc/hosts
to use 127.0.0.1 localhost.com
).setcookie(
$AUTH_COOKIE_NAME,
$cookie_value,
time() + cookie_expiration(),
$BASE_DIRECTORY,
null,
false,
true
);
null
indicates that the domain should not be set.