浏览记录实现思路及方法

之前想过用cookie来实现这个,但是cookie不能存放数组,而且也不好实现,就用了session方法

//将用户浏览过的商品保存到session里,可以在浏览记录里显示
        
        $_SESSION['recent_products'][] =$id;
        $_SESSION['recent_products']=array_unique($_SESSION['recent_products']);
        $recentgoods=array();
        foreach ($_SESSION['recent_products'] as $k=>$v){
            if(Db::table('sp_goods')->where('id',$v)->field('sm_thumb,goods_name,id,shop_price')->find()){
                $recentgoods[]=Db::table('sp_goods')->where('id',$v)->field('sm_thumb,goods_name,id,shop_price')->find();
            }

        }
        $this->assign('recentgoods',$recentgoods);

猜你喜欢

转载自www.cnblogs.com/jcydd/p/10627987.html