这是我在javascript中设置cookie和在php中读取cookie的代码。
jsglobalset.html:
<script>
var values = "poppy"
document.cookie = "textout=" + values + "; path=/";
</script>
phpglobalread.php:
<?php
$messsage = $_COOKIE["textout"];
if($message != "") { echo $message; }
else { echo "Fail to read."; }
?>
phpglobalread.html的输出:
Fail to read.
我尝试在javascript中阅读cookie并且它有效,但我无法在php中阅读。有任何想法吗?感谢。
答案 0 :(得分:1)
<?php
$messsage = $_COOKIE["textout"];
if($message != "") { echo $message; }
else { echo "Fail to read."; }
?>
你说$ messsage = $ _COOKIE [“textout”]; ,但在你的IF上你的var是$ message而不是$ messsage。
尝试:
<?php
$message = $_COOKIE["textout"];
if($message != "") { echo $message; }
else { echo "Fail to read."; }
?>