Home > php教程 > php手册 > 用户的浏览商品记录功能代码

用户的浏览商品记录功能代码

WBOY
Release: 2016-06-07 11:35:38
Original
1622 people have browsed it

用户的浏览商品记录功能代码
/**<br>  * 车辆历史浏览记录<br>  * $data 车辆记录信息<br>  */<br> protected function _history($data)<br> {<br>   if(!$data || !is_array($data))<br>   {<br>     return false;<br>   }<br>   //判断cookie类里面是否有浏览记录<br>   if($_COOKIE['history_car'])<br>   {<br>     $history = unserialize($_COOKIE['history_car']);<br>     array_unshift($history, $data); //在浏览记录顶部加入<br>     /* 去除重复记录 */<br>     $rows = array();<br>     foreach ($history as $v)<br>     {<br>       if(in_array($v, $rows))<br>       {<br>         continue;<br>       }<br>       $rows[] = $v;<br>     }<br>     /* 如果记录数量多余5则去除 */<br>     while (count($rows) > 5)<br>     {<br>       array_pop($rows); //弹出<br>     }<br>     setcookie('history_car',serialize($rows),time()+3600*24*30,'/');<br>   }<br>   else<br>   {<br>     $history = serialize(array($data));<br>     setcookie('history_car',$history,time()+3600*24*30,'/');<br>   }<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template