PHP记录商品历史纪录

/* 记录浏览历史 */
if (!empty($_COOKIE['history']))
{
    if(stripos($_COOKIE['history'].',',$goods_id.',')===false){
        
        $history = explode(',', $_COOKIE['history']);

        array_unshift($history, $goods_id); //入栈
        
    
        while (count($history) > 5) //大于容器容量
        {
            array_pop($history); //出栈
        }
    
        setcookie('history', implode(',', $history), gmtime() + 3600 * 24 * 30); 
    }
}
else
{
    setcookie('history', $goods_id, gmtime() + 3600 * 24 * 30);
}

 

posted @ 2013-11-10 17:52  jshaibozhong  阅读(317)  评论(0编辑  收藏  举报