不知道我做錯了......setcookie()函數不工作
這裏是用來設置的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);
正如你可以在測試頁面看到,餅乾總是空
仍在尋找解決方案... – anarchOi 2013-03-08 21:06:14