<?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));
  }
    }
?>请高手帮忙看看吧!这里一直保存不下来!

解决方案 »

  1.   

    我在chrome上测试了一下你的代码,它工作正常啊
    我只改写了数据库查询那段 $rs = array('pid'=>12)
    cookie中的数据经过urldecode()后为 a:1:{i:0;a:1:{i:0;i:12;}}
    不知道你说的不能保存是什么情况。setcookie()前不能有输出包括空格BOM头,这你确定吗?
      

  2.   

    setcookie("product_see",serialize($current)); ???
    你没有指出失效期,cookie 不会被保存
      

  3.   


    可以给个联系方式 帮忙看看么?我是PHP新手 谢谢!