首页 > Web开发 > 详细

php浏览历史记录

时间:2016-12-01 16:20:26      阅读:258      评论:0      收藏:0      [点我收藏+]
/**
 * 商品历史浏览记录
 * $data 商品记录信息
 */
private function _history($data)
{
    if(!$data || !is_array($data))
    {
        return false;
    }
     
    //判断cookie类里面是否有浏览记录
    if($this->_request->getCookie(‘history‘))
    {
        $history = unserialize($this->_request->getCookie(‘history‘));
        array_unshift($history, $data); //在浏览记录顶部加入
 
        /* 去除重复记录 */
        $rows = array();
        foreach ($history as $v)
        {
            if(in_array($v, $rows))
            {
                continue;
            }
            $rows[] = $v;
        }
 
        /* 如果记录数量多余5则去除 */
        while (count($rows) > 5)
        {
            array_pop($rows); //弹出
        }
 
        setcookie(‘history‘,serialize($rows),time() + 3600 * 24 * 30,‘/‘);
    }
    else
    {
        $history = serialize(array($data));
 
        setcookie(‘history‘,$history,time() + 3600 * 24 * 30,‘/‘);
    }
}

 

php浏览历史记录

原文:http://www.cnblogs.com/xujing6/p/6122378.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!