Hello,
I am trying to create a feature on my site that will track which pages the user has gone to and then display the last 4 in an area called Recently Viewed.
I got a little bit starting with it, I basically am logging every view into a cookie on the users computer. I am stumbling at the part of making sure I dont have the same page twice in the listings.
What is the best way to do this? I was thinking of using an array to store the value from the cookie and then searching to see if the current page is already in the array. If it is then skip it, else set the cookie.
Here is my script so far:
[code=php]if ($n_pages > 0) {
if (isset($_COOKIE[“recentlyviewed”])) {
$store = $_COOKIE[“recentlyviewed”];
$store .= “/”.$current_category[“id”].”&”.$current_category[“name”];
//setcookie(“recentlyviewed”, urldecode($store), time()+36000, “/”);
echo $_COOKIE[“recentlyviewed”];
} else {
$store = $current_category[“id”].”&”.$current_category[“name”];
setcookie(“recentlyviewed”, urldecode($store), time()+36000, “/”);
}
}
NOTE: I am grabbing the artists ID and name and storing it in the cookie. I want to only keep 4 pages in the cookie.
Any ideas?