php 浏览商品记录,php浏览历史记录
php瀏覽歷史記錄
/**
* 商品歷史瀏覽記錄
* $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;
}
/* 如果記錄數(shù)量多余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,'/');
}
}
開心洋蔥 , 版權(quán)所有丨如未注明 , 均為原創(chuàng)丨未經(jīng)授權(quán)請勿修改 , 轉(zhuǎn)載請注明php瀏覽歷史記錄!
總結(jié)
以上是生活随笔為你收集整理的php 浏览商品记录,php浏览历史记录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql+用户批量导出,python批
- 下一篇: python 小波去噪,用Pywavel