㈠ 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;
}
/* 如果記銷鬧錄數量多餘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,'/');
}
}