PHP setcookie指定domain参数后,在IE下设置cookie失效的解决方法
setcookie
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在所有子域名通用的话,可以通过全局变量来变通的实现。
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
1 weeks ago
By DDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Where to find the Crane Control Keycard in Atomfall
1 weeks ago
By DDD

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
CakePHP Tutorial
1359
52

