<?php
$temp_arr = stripslashes($_COOKIE['product_see']);
$current=unserialize($temp_arr);//当前已看过的商品二维数组
$temp_num=count($current);
if($temp_num>3)//这里只记录最多4个足迹
{
$current=array_reverse($current);
array_pop($current);//反转数组后弹出最后一个元素(也就是第一个元素)
$current=array_reverse($current);//再反转回正确的排序
$temp_num=3;
}
$sql="select * from pro3_products where pid=".$_REQUEST['id'];
$command=mysql_query($sql);
$rs=mysql_fetch_array($command);
if($_COOKIE['product_see']=="")//如果一个商品也没看过则存入
{
$current[0][0]=$rs['pid'];//id
setcookie("product_see",serialize($current));
}
else
{
//否则判断当前商品ID和数组中存的ID是否有一样的
$temp_s=0;
foreach($current as $key => $value)
{
foreach($current[$key] as $key2 => $value2)
{
//echo $key2." => ".$value2;
if($value2==$rs['pid'])
{
//有本产品的记录则不操作
$temp_s=1;
}
}
}
if($temp_s==0)//如果没一样的则记录下来
{
$current[$temp_num][0]=$rs['pid'];
setcookie("product_see",serialize($current));
}
}
?>请高手帮忙看看吧!这里一直保存不下来!
$temp_arr = stripslashes($_COOKIE['product_see']);
$current=unserialize($temp_arr);//当前已看过的商品二维数组
$temp_num=count($current);
if($temp_num>3)//这里只记录最多4个足迹
{
$current=array_reverse($current);
array_pop($current);//反转数组后弹出最后一个元素(也就是第一个元素)
$current=array_reverse($current);//再反转回正确的排序
$temp_num=3;
}
$sql="select * from pro3_products where pid=".$_REQUEST['id'];
$command=mysql_query($sql);
$rs=mysql_fetch_array($command);
if($_COOKIE['product_see']=="")//如果一个商品也没看过则存入
{
$current[0][0]=$rs['pid'];//id
setcookie("product_see",serialize($current));
}
else
{
//否则判断当前商品ID和数组中存的ID是否有一样的
$temp_s=0;
foreach($current as $key => $value)
{
foreach($current[$key] as $key2 => $value2)
{
//echo $key2." => ".$value2;
if($value2==$rs['pid'])
{
//有本产品的记录则不操作
$temp_s=1;
}
}
}
if($temp_s==0)//如果没一样的则记录下来
{
$current[$temp_num][0]=$rs['pid'];
setcookie("product_see",serialize($current));
}
}
?>请高手帮忙看看吧!这里一直保存不下来!
解决方案 »
- 灵异事件.快来看strstr 和 strpos 把两个不同的字符串匹配成功了.
- 数组分解?
- 请教snnopy的一个方法!
- 请问 delphi for php 2.0 注册码
- 急!乱码问题 Dreamweaver 8 导出MYSQL数据 出现了"?"
- php 怎么响应button的onclick事件
- 能否用PHP做网络游戏呢?
- 请高手给个意见,是学PHP好呢,还是ASP呢; 数据库方面是学MYSQL呢还是SQL SEVER好呢
- 我用COM类生成*.xls文件为什么会出这种错??
- mysql.exe 打不开,双击后屏幕闪动一下就没了,怎么回事,能弄好吗
- 请高手解决php中小弟关于$这个符号的疑问!~~~
- 如何获取CURL读取远程html后完成时的状态?
我只改写了数据库查询那段 $rs = array('pid'=>12)
cookie中的数据经过urldecode()后为 a:1:{i:0;a:1:{i:0;i:12;}}
不知道你说的不能保存是什么情况。setcookie()前不能有输出包括空格BOM头,这你确定吗?
你没有指出失效期,cookie 不会被保存
可以给个联系方式 帮忙看看么?我是PHP新手 谢谢!