PHP
·
发表于 5年以前
·
阅读量:8410
±¾ÎÄʵÀý½²ÊoÁËphpa¯ÀÀÀuʼǼµÄ½¨¡£ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼¡£¾ßÌaʵÏÖ½¨ÈçÏ£º
/**
* ÉÌÆ*ÀuÊ*a¯ÀÀ¼Ç¼
* $data ÉÌÆ*¼Ç¼ÐÅÏ¢
*/
private function _history($data)
{
if(!$data || !is_array($data))
{
return false;
}
//ÅжÏcookieÀaÀiÃaeÊÇ*ñÓÐa¯ÀÀ¼Ç¼
if($this->_request->getCookie('history'))
{
$history = unserialize($this->_request->getCookie('history'));
array_unshift($history, $data); //ÔÚa¯ÀÀ¼Ç¼¶¥²¿¼ÓÈe
/* È¥³ýÖظ´¼Ç¼ */
$rows = array();
foreach ($history as $v)
{
if(in_array($v, $rows))
{
continue;
}
$rows[] = $v;
}
/* Èç¹u¼Ç¼ÊýÁ¿¶aÓa5ÔoÈ¥³ý */
while (count($rows) > 5)
{
array_pop($rows); //µ¯³o
}
setcookie('history',serialize($rows),time()+3600*24*30,'/');
}
else
{
$history = serialize(array($data));
setcookie('history',$history,time()+3600*24*30,'/');
}
}
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼ÒµÄphp³ÌÐoÉe¼ÆÓÐËu°iÖu¡£