不知道我做错了什么......
这是用于设置 cookie 的页面: https ://www.ni-dieu-ni-maitre.com/test.php
$domain = "ni-dieu-ni-maitre.com";
$articleid = "test";
$lastviewedarticles = array();
if (isset($_COOKIE["viewed_articles"]) ) {
$lastviewedarticles = unserialize($_COOKIE["viewed_articles"]);
}
if (!in_array($articleid, $lastviewedarticles)){
$count = count($lastviewedarticles);
if($count>=29)
array_shift($lastviewedarticles);
$lastviewedarticles[] = $articleid;
}
setcookie('viewed_articles', serialize($lastviewedarticles), time()+60*60*24*30, '/', '.' . $domain);
然后这个页面读取cookie并输出内容: https ://www.ni-dieu-ni-maitre.com/test2.php
if ( isset($_COOKIE["viewed_articles"]) ) {
$lastviewedarticles = unserialize($_COOKIE["viewed_articles"]);
}
echo "cookie is currently:<br>";
print_r($lastviewedarticles);
正如您在测试页面上看到的那样,cookie 始终为空