php session购物车问题

WBOY
Release: 2016-06-23 14:27:13
Original
943 people have browsed it

class CartTool    {        private static $ins;        private $good = array();               final private function __construct()        {                    }        final private function __clone()        {                    }                // 获取实例        protected static function getIns()         {        if(!(self::$ins instanceof self))         {            self::$ins = new self();        }        return self::$ins;    }                        /**         * 函数作用:把购物车的单例对象放到session里         *          *          * @return instance 购物车的单例对象         * */        public static function getCart()         {        if(!isset($_SESSION['cart']) || !($_SESSION['cart'] instanceof self))         {            echo '1';            $_SESSION['cart'] = self::getIns();        }        return $_SESSION['cart'];    }
Copy after login


这是我的购物车类(部分),我在页面直接引用它使用不会出现任何问题,但是在有一将它放入一序列的初始化类中在引用它的时候就会产生了一个问题,每次它都会重新生成过,就没有了单例的效果。不知道我的问题描述清楚了没有,请各位高手给小弟一点建议或者思路,有可能哪里出问题了???


回复讨论(解决方案)

建议换个思路实现。
用SESSION ID或者一个cookie变量做标志。

把其它信息都存起来,memcached或mysql都可以。

恩,我后来用mysql

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template