I've been using this script since a few months and it was working perfectly until i switched host (and php version)
Basically the script is used to put the page ID inside an array in a cookie, each time a page is visited.
Then on another page, the list of the last visited page ID's
Here is the first part that will put the page ID inside a cookie:
$articleid = "test";
$domain = "ni-dieu-ni-maitre.com";
$lastviewedarticles = array();
if (isset($_COOKIE["viewed_articles"]) ) {
$lastviewedarticles = unserialize($_COOKIE["viewed_articles"]);
}
if (!in_array($articleid, $lastviewedarticles)){
$count = count($lastviewedarticles);
if($count>=50)
array_shift($lastviewedarticles);
$lastviewedarticles[] = $articleid;
}
$cookiedomain = ".$domain";
setcookie('viewed_articles', serialize($lastviewedarticles), time()+60*60*24*30, '/', $cookiedomain);
And now the second part that will output the list of the last 5 visited page id's:
if ( isset($_COOKIE["viewed_articles"]) ) {
$lastviewedarticles = unserialize($_COOKIE["viewed_articles"]);
}
$lastviewedarticles = array_reverse($lastviewedarticles);
$numrecent = count($lastviewedarticles);
if ($numrecent >= 1) {
$i = 0;
foreach ($lastviewedarticles as $recent) {
echo "$recent<br>";
}
$i++;
if($i >= 4) {
break;
}
}
}
Any idea why it suddently stopped working ? I don't remember having edited something since a while.