Home > php教程 > php手册 > body text

PHP setcookie指定domain参数后,在IE下设置cookie失效的解决方法

WBOY
Release: 2016-06-06 20:38:39
Original
1114 people have browsed it

setcookie函数指定domain参数后,在IE下的表现和在chrome、firefox中的表现不同,这不是php setcookie函数的问题,这是IE的问题。

下面的代码:在chrome和firefox下可以生成三个cookie:
cookie[one]、cookie[two]、cookie[three]
在IE下,只能生成cookie[one]、cookie[two]两个cookie,第三个因为指定了”.65.la”,导致cookie[three]生成失败。
代码如下:
setcookie(“cookie[one]“, “cookieone”,time()+36000,”/”);
setcookie(“cookie[two]“, “cookietwo”,time()+36000,”/”);
setcookie(“cookie[three]“, “cookiethree”, time()+36000,”/”,”.65.la”);
// 页面重新
if (isset($_COOKIE["cookie"])) {
foreach ($_COOKIE["cookie"] as $name => $value) {
$name = htmlspecialchars($name);
$value = htmlspecialchars($value);
echo “$name : $value
\n”;
}
}
?>

多次实验之后,确认IE认为”.65.la”这种形式的域名参数是不规范的。如果要cookie在所有子域名通用的话,可以通过全局变量来变通的实现。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template