Tracking the user’s browsing history with PHP and cookie

Here is a sample code to show how using php and cookie to tracking the user’s browsing history. The code is used on a shopping website.
Hope it helpful to you.

/* browsing history */
if (!empty($_COOKIE['ECS']['history']))
{
   $history = explode(’,', $_COOKIE['ECS']['history']);

   array_unshift($history, $goods_id);
   $history = array_unique($history);

   while (count($history) > $_CFG['history_number'])
   {
      array_pop($history);
   }

   setcookie(’ECS[history]‘, implode(’,', $history), gmtime() + 3600 * 24 * 30);

} else {

   setcookie(’ECS[history]‘, $goods_id, gmtime() + 3600 * 24 * 30);

}
affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Comments are closed.