0

何が間違っているのかわからない...

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);

テスト ページでわかるように、Cookie は WWW なしでは常に空です。Cookie には配列がありますが、常に空です

4

0 に答える 0