我无法获取Cookie值。我的cookie在浏览器中可用。当我设置cookie时,它将显示并正常工作,但是几个小时后,我无法从cookie获得任何响应。
$cookie_name = "token";
$cookie_value = $value;
setcookie($cookie_name);
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/", '.example.com');
echo $_COOKIE[token];
答案 0 :(得分:0)
您忘记了cookie名称周围的引号
$cookie_name = "token";
$cookie_value = $value;
setcookie($cookie_name);
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/", '.example.com');
echo $_COOKIE['token']; //[token] > ['token']
答案 1 :(得分:0)
引用token
时您刚刚忘记了引号。如果将其作为变量,为什么不使用它呢?
$cookie_name = "token";
$cookie_value = $value;
setcookie($cookie_name);
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/", '.example.com');
echo $_COOKIE[$cookie_name];
答案 2 :(得分:0)
只需替换
echo $_COOKIE[token];
与此:
echo $_COOKIE['token'];
您尚未添加带有cookie名称的引号。