PHP实现浏览历史记录
很多网站均有这样的功能,特别是一些购物网站均设计有浏览历史这样一个特色的功能,当然了实现的方法是多种多样的。asp、php、jsp等等均可以实现。下面我们以PHP为例来演示一下。源代码为ecshop里面的一段,算是比较经典的写法。
PHP实现浏览历史记录源码如下:
if (!empty($_COOKIE['ECS']['history']))
{
$history = explode(’,', $_COOKIE['ECS']['history']);
array_unshift($history, $goods_id);
$history = array_unique($history);
while (count($history) > $_CFG['history_number'])
{
array_pop($history);
}
setcookie(’ECS[history]‘, implode(’,', $history), gmtime() + 3600 * 24 * 30);
}
else
{
setcookie(’ECS[history]‘, $goods_id, gmtime() + 3600 * 24 * 30);
}
更新时间:2010-5-19
|