用户登录时,网站将为用户名和ID设置cookie。这些文件将保留30天,并且整个网站都可以访问。尽管经过漫长的开发之夜,我遇到了很大的困难,但对于我的一生,我仍然无法弄清楚为什么在毫无疑问的情况下,cookie会以“ null”响应。
**This sets
setcookie('userid', '1', time() + 30, '/', 'example.com');
setcookie('useruid', 'blah', time() + 30, '/', 'example.com');
//setcookie('userid', '', time() -3600); **To remove when logging out
header("location: https://www.example.com/");
**This reads
if (isset($_COOKIE['userid']))
{
$userUid = $_COOKIE['useruid'];
echo '<a href="https://account.example.com/login/">'.$userUid.'</a>';
} else {
echo '<script type="text/javascript">
window.location.replace("https://account.example.com/login/");
</script>';
}
我希望用户名显示在标题中,并且可以在整个网站(顶级域,子域等)中访问
这是Chrome浏览器看到的(之前):https://ibb.co/pJPTrSN
这是Chrome看到的(在-> ID之后):https://ibb.co/fpPNTks
这是Chrome看到的(在-> UID之后):https://ibb.co/4tg1q7x
预先感谢...