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

One Response to “Tracking the user’s browsing history with PHP and cookie”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>