<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cookie &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/cookie/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Mon, 01 Oct 2012 12:30:06 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>
	<item>
		<title>php利用cookie记录用户浏览记录</title>
		<link>https://www.mudbest.com/php%e5%88%a9%e7%94%a8cookie%e8%ae%b0%e5%bd%95%e7%94%a8%e6%88%b7%e6%b5%8f%e8%a7%88%e8%ae%b0%e5%bd%95/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 17 Mar 2011 15:52:53 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cookie]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=476</guid>

					<description><![CDATA[主要是通过操作数组来实现的，所以用到一些操作数组的函数。 不懂的查查手册就知道了。]]></description>
										<content:encoded><![CDATA[<pre class="brush: php; title: ; notranslate">
/* 记录浏览历史 */
//如是COOKIE 里面不为空，则往里面增加一个商品ID
if (!empty($_COOKIE&#x5B;'SHOP']&#x5B;'history']))
{

//取得COOKIE里面的值，并用逗号把它切割成一个数组
$history = explode(',', $_COOKIE&#x5B;'SHOP']&#x5B;'history']);
//在这个数组的开头插入当前正在浏览的商品ID
array_unshift($history, $id);
//去除数组里重复的值
$history = array_unique($history);
// $arr = array (1,2,3,1,3);
// $arr = array (1,1,2,3,3);
// $arr = array (1,2,3);
//当数组的长度大于5里循环执行里面的代码
while (count($history) &gt; 5)
{
//将数组最后一个单元弹出，直到它的长度小于等于5为止
array_pop($history);
}

//把这个数组用逗号连成一个字符串写入COOKIE，并设置其过期时间为30天
setcookie('SHOP&#x5B;history]', implode(',', $history), $cur_time + 3600 * 24 * 30);
}
else
{
//如果COOKIE里面为空，则把当前浏览的商品ID写入COOKIE ，这个只在第一次浏览该网站时发生
setcookie('SHOP&#x5B;history]', $id, $cur_time + 3600 * 24 * 30);

}

//以上均为记录浏览的商品ID到COOKIE里,下面将讲到怎样用这样COOKIE里的数据

//取得COOKIE里的数据 ,格式为1,2,3,4 这样，当然也有可以为0
$history =isset ($_COOKIE&#x5B;'SHOP']&#x5B;'history']) ? $_COOKIE&#x5B;'SHOP']&#x5B;'history'] : 0;
//写SQL语句，用IN 来查询出这些ID的商品列表
$sql_history = &quot;SELECT * FROM `goods` WHERE `goods_id` in ({$history})&quot;;
//执行SQL语句，返回数据列表
$goods_history = $db-&gt;getAll($sql_history);
if ($goods_history) {
$tpl-&gt;assign ('goods_history',$goods_history);
}
</pre>
<p>主要是通过操作数组来实现的，所以用到一些操作数组的函数。<br />
不懂的查查手册就知道了。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
