What to do if setcookie php fails

藏色散人
Release: 2023-03-17 09:24:02
Original
1771 people have browsed it

The solution to setcookie php failure: 1. Open the corresponding PHP file; 2. Check whether the domain name parameters are standardized; 3. Use global variables to achieve it, code such as "foreach ($_COOKIE["cookie" ] as $name => $value) {$name = htmlspecialchars($name);$value = htmlspecialchars($value);echo...".

What to do if setcookie php fails

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What should I do if setcookie php fails?

Specific problem description:

After PHP setcookie specifies the domain parameter, the cookie set under IE fails?

Solution

The following code: three cookies can be generated under chrome and firefox:

cookie[one]、cookie[two]、cookie[three]
Copy after login

Under IE, only cookie[one], cookie[ two] two cookies, the third cookie [three] failed to be generated because ".65.la" was specified.

The code is as follows:

<?php
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 <br />\n”;
}
}
?>
Copy after login

After many experiments, it is confirmed that IE considers domain name parameters in the form of ".65.la" to be irregular. If you want the cookie to be common to all subdomains, you can implement it through global variables.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if setcookie php fails. For more information, please follow other related articles on the PHP Chinese website!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template