不确定我做错了什么......
以下是用于设置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://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);
正如您在测试页面上看到的那样,没有WWW,cookie总是空的。 Cookie中有一个数组,但它总是空的