Home > php教程 > php手册 > body text

php浏览历史记录的方法

WBOY
Release: 2016-06-06 20:06:57
Original
2563 people have browsed it

这篇文章主要介绍了php浏览历史记录的方法,涉及php操作cookie的技巧,非常具有实用价值,需要的朋友可以参考下

本文实例讲述了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,'http://www.jb51.net/'); } else { $history = serialize(array($data)); setcookie('history',$history,time()+3600*24*30,'http://www.jb51.net/'); } }

希望本文所述对大家的php程序设计有所帮助。

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!