$value) {$name = htmlspecialchars($name);$value = htmlspecialchars($value);echo..."."/> $value) {$name = htmlspecialchars($name);$value = htmlspecialchars($value);echo...".">
Home >Backend Development >PHP Problem >What to do if setcookie php fails
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...".
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]
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”; } } ?>
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!