本人新手,刚接触php 2~3天setcookie以后取不到变量值
代码简化到test.php
<?php
setcookie("usrname","a fool");
?><?php
if(isset($_COOKIE["usrname"]){echo $_COOKIE["usrname"];}
else{ echo "big error";}
?>仍然不能解决问题
添加路径以后也不能解决问题
$_COOKIE["usrname"]始终为空值,用$HTTP_COOKIE_VARS["usrname"]也不能取到
不知问题何在,翻了一些资料也不能找到解决方法
代码简化到test.php
<?php
setcookie("usrname","a fool");
?><?php
if(isset($_COOKIE["usrname"]){echo $_COOKIE["usrname"];}
else{ echo "big error";}
?>仍然不能解决问题
添加路径以后也不能解决问题
$_COOKIE["usrname"]始终为空值,用$HTTP_COOKIE_VARS["usrname"]也不能取到
不知问题何在,翻了一些资料也不能找到解决方法
一個頁面設置cookie,到另外一個頁面使用的時候顯示不了值,那你必須得在頁面的最前加session_id(PHPSESSID);PHPSESSID是你設置session_id的名字,與你的配置文件php.ini設置的名字一樣,有些設成SID,那就寫SID
php.net/setcookie
defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction).
$expire = time() + 60 * 60 * 24 * $expire_day;
setcookie("usrname","a fool",$expire,"/");If set to '/', the cookie will be available within the entire domain.