首页 > PHP > php 利用cookie在客户端记录浏览历史

php 利用cookie在客户端记录浏览历史

/* 记录浏览历史 */
if (!empty($_COOKIE[‘history’]))
{
if(stripos($_COOKIE[‘history’].’,’,$goods_id.’,’)===false){

$history = explode(‘,’, $_COOKIE[‘history’]);

array_unshift($history, $goods_id); //入栈

while (count($history) > 5) //大于容器容量
{
array_pop($history); //出栈
}

setcookie(‘history’, implode(‘,’, $history), gmtime() + 3600 * 24 * 30);
}
}
else
{
setcookie(‘history’, $goods_id, gmtime() + 3600 * 24 * 30);
}

分类:PHP 标签:,
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: