Not sure what i am doing wrong...
$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);
Then this page reads the cookie and output the content:
if ( isset($_COOKIE["viewed_articles"]) ) {
$lastviewedarticles = unserialize($_COOKIE["viewed_articles"]);
}
echo "cookie is currently:<br>";
print_r($lastviewedarticles);
As you can see on the test pages, the cookies are always empty