public function logout() { /** * 保存客户购物车中的所购买的产品与收藏产品 */ $ip = wcore_utils::get_ip(); $cartlist = $this->mdb()->escape(isset($this->session->data['cart']) ? serialize($this->session->data['cart']) : ''); $wishlist = $this->mdb()->escape(isset($this->session->data['wishlist']) ? serialize($this->session->data['wishlist']) : ''); $this->mdb()->query_res("UPDATE " . DB_PREFIX . "customer SET cart = '{$cartlist}', wishlist = '{$wishlist}', ip = '{$ip}' WHERE customer_id = '{$this->customer_id}'"); /** * 清除登录信息 */ $this->customer_id = ''; $this->firstname = ''; $this->lastname = ''; $this->email = ''; $this->telephone = ''; $this->fax = ''; $this->newsletter = ''; $this->customer_group_id = ''; $this->address_id = ''; unset($this->session->data['customer_id']); wcore_utils::set_cookie('cust_id', null, -1); wcore_utils::set_cookie('cust_email', null, -1); }
/** * 初始化SESSION * * @param string $type 会话的存储方式 * @param integer $ltime 会话寿命时间以分钟为单位 * @param string $path 会话文件存储的路径 * @param string $prefix 会话文件前缀 * @param boolean $start 是否马上启用SESSION处理 */ public function __construct($type = 'file', $ltime = 30, $path = '', $prefix = 'ws', $start = true) { $this->_prefix = $prefix; $this->_type = strtolower($type); if ($this->_type == 'file' || $this->_type == 'dir') { $this->_path = $path && file_exists($path) ? $path : get_cfg_var('session.save_path'); wcore_fso::make_dir($this->_path); //处理SESSION存储的路径 } $this->_life_time = $ltime && is_numeric($ltime) ? $ltime * 60 : get_cfg_var('session.gc_maxlifetime'); $this->_ip = wcore_utils::get_ip(); session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc')); register_shutdown_function('session_write_close'); /** * 是否马上启用SESSION处理 */ if ($start) { ini_set('session.use_cookies', 'On'); ini_set('session.use_trans_sid', 'Off'); session_set_cookie_params(0, '/'); session_start(); } $this->data =& $_SESSION; }
/** * 将IP地址转换成长整形数据 * * @param string $ip ip地址 * @return long ip长整形 */ public static function get_ip_long($ip = '') { $ip = $ip ? $ip : wcore_utils::get_ip(); $ip = ip2long($ip); //将IP转换成数字 //ip转数字无效返回false if ($ip === false) { return false; } return sprintf('%u', $ip); //将转换成数字的IP再次转换成无符号的长整形 }