$ _COOKIE []不接受带句点的字符串?
问题描述:
<?php
$Test = "dsdsdad.dsad";
if (isset($_COOKIE["$Test"])) {
echo "I GOT A COOKIE WITH A PERIOD";
} else {
setcookie("$Test", "yes", time()+60*60*24*3);
}
$Test = "dsdsdaddsad";
if (isset($_COOKIE["$Test"])) {
echo "I GOT A COOKIE WITHOUT A PERIOD";
} else {
setcookie("$Test", "yes", time()+60*60*24*3);
}
?>
It seems that $_COOKIE[] will not accept anything with a period in it. However, the setcookie function sets both cookies fine. What is the way around this? I'd like it to read a cookie with a dot.
&lt;?php
$ Test =“dsdsdad.dsad”;
if( isset($ _ COOKIE [“$ Test”])){
echo“I GOT A COOKIE WITH A PERIOD”;
} else {
setcookie(“$ Test”,“yes”,time()+ 60 * 60 * 24 * 3);
}
$ Test =“dsdsdaddsad”;
if(isset($ _ COOKIE [“$ Test”])){
echo“I GOT A COOKIE WITHOUT A PERIOD“;
} else {
setcookie(”$ Test“,”yes“,time()+ 60 * 60 * 24 * 3);
}
?&gt;
code> pre>
似乎$ _COOKIE []不会接受带有句号的任何内容。 但是,setcookie功能可以很好地设置两个cookie。 这是怎么回事? 我希望它能用点读取一个cookie。 p>
div>
答
Please see the documentation.
So, if you set the cookie dsdsdad.dsad
, it'll be stored as dsdsdad_dsad
when PHP parses the cookie headers..