function _initialize() { header("Content-Type:text/html; charset=utf-8"); //获取国家列表 self::$Model = D("Region"); $this->Countries = self::$Model->where("type=0")->order('name asc')->select(); //主题 if ($this->theme = GetValue('theme')) { } else { $this->theme = 'default'; } //货币 L('_OPERATION_SUCCESS_', "Operation Success"); L('_OPERATION_FAIL_', 'Operation Fail'); //$this->currencies=get_currencies_arr(); //生产一个唯一的session id $this->sessionID = Cookie::get('sessionID'); if (!$this->sessionID) { $this->sessionID = create_session_id(); Cookie::set('sessionID', $this->sessionID); } //读取用户id $auth_cookie = Cookie::get('auth'); if (empty($auth_cookie)) { $this->memberID = 0; Session::set('back', $_SERVER['REQUEST_URI']); } else { $auth = daddslashes(explode("\t", authcode($auth_cookie, 'DECODE', C('AUTHKEY')))); list($member_id, $member_email) = empty($auth) || count($auth) < 2 ? array('', '') : $auth; if (!empty($member_id)) { $this->memberID = $member_id; } } Cookie::set('memberID', $this->memberID); if ($this->memberID) { //读取用户信息 $this->mid = $this->memberID; self::$Model = D("Members"); $this->member_Info = $this->memberInfo = self::$Model->where("id=" . $this->memberID)->find(); self::$Model = D("Shippingaddress"); $this->memberShippingAddress = self::$Model->where("id=" . $this->memberID)->find(); } //购物车商品 self::$Model = D("Cart"); $this->cart_list = self::$Model->cart_list($this->sessionID); $this->item_count = itemCount(); $this->total_count = TotalCount(); if (F('Common_Cache')) { $this->assign(F('Common_Cache')); } }
public function _initialize() { header("Content-Type:text/html; charset=utf-8"); //是否关闭网站 if (GetValue('close_site') == 1) { header("HTTP/1.1 500 Internal Server Error"); header("Status: 500 Internal Server Error"); die('<div style="margin: 10px; text-align: center; font-size: 14px"><p>The temporary closure of this site, you can not access!</p><p>' . GetValue('close_site_content') . '</p></div>'); } //IP封锁 if (isset($_COOKIE['ipblock']) && $_COOKIE['ipblock'] == 0) { } elseif (isset($_COOKIE['ipblock']) && $_COOKIE["ipblock"] == 1 || GetValue('ipblock') == 1 && GetValue('ipblock_pwd') != '') { $ipblock = new Home\Controller\IpblockController(); $ipblock->index(); } //货币初始化 $currencies = get_currencies_arr(); if (!isset($_SESSION['currency'])) { for ($i = 0; $i < count($currencies); $i++) { if ($currencies[$i]['symbol'] == C('DEFAULT_CURRENCIES_SYMBOL')) { session('currency', $currencies[$i]); } } } $this->assign('currencies', $currencies); //生产一个唯一的session id $this->sessionID = cookie('sessionID'); if (!$this->sessionID) { $this->sessionID = create_session_id(); cookie('sessionID', $this->sessionID); } //读取用户id $auth_cookie = cookie('auth'); if (empty($auth_cookie)) { $this->memberID = 0; } else { $auth = daddslashes(explode("\t", authcode($auth_cookie, 'DECODE', C('AUTHKEY')))); list($member_id, $member_email) = empty($auth) || count($auth) < 2 ? array('', '') : $auth; if (!empty($member_id)) { $this->memberID = $member_id; } } cookie('memberID', $this->memberID); if ($this->memberID) { //读取用户信息 $this->mid = $this->memberID; $this->member_Info = D("Members")->where("id=" . $this->memberID)->find(); $this->assign('member_Info', $this->member_Info); $this->member_ShippingAddress = D("Shippingaddress")->get_shippingaddress($this->memberID); } $this->assign('memberID', $this->memberID); $referer = ''; if (isset($_GET['referer']) && $_GET['referer']) { $referer = $_GET['referer']; } else { if (cookie('referer')) { $referer = cookie('referer'); } } $this->referer = $referer; //当前月份 $today = getdate(); $this->month = $today['month']; //会员等级 $this->memberGropuInfo = get_members_group($this->memberID); $this->isVip = $this->memberGropuInfo ? 1 : 0; $this->ProModel = D('Products'); $this->assign('catetree', get_catetree()); $this->assign('itemCount', itemCount()); $this->assign('copyright', GetValue('footer_content')); $this->assign('tongji', GetValue('footcode')); }
function _initialize() { header("Content-Type:text/html; charset=utf-8"); L('_OPERATION_SUCCESS_', "Operation Success"); L('_OPERATION_FAIL_', 'Operation Fail'); //是否关闭网站 if (GetValue('close_site') == 1) { header("HTTP/1.1 500 Internal Server Error"); header("Status: 500 Internal Server Error"); die('<div style="margin: 10px; text-align: center; font-size: 14px"><p>The temporary closure of this site, you can not access!</p><p>' . GetValue('close_site_content') . '</p></div>'); } //IP封锁 if (isset($_COOKIE['ipblock']) && $_COOKIE['ipblock'] == 0) { } elseif (isset($_COOKIE['ipblock']) && $_COOKIE["ipblock"] == 1 || GetValue('ipblock') == 1 && GetValue('ipblock_pwd') != '') { import('@.Action.Home.IpblockAction'); $ipblock = new IpblockAction(); $ipblock->index(); } $this->ProModel = D('Products'); //多主题 if ($this->theme = GetValue('theme')) { setcookie('think_template', $this->theme, time() + 3600, '/'); } else { setcookie('think_template', 'default', time() + 3600, '/'); } //多语言 /*$lang=GetValue('lang'); if('auto'!=$lang){ setcookie('think_language',$lang?$lang:'en-us',time()+3600,'/'); }*/ //浏览历史 $this->product_history = product_history(); //货币初始化 $this->currencies = $currencies = get_currencies_arr(); if (!isset($_SESSION['currency'])) { for ($row = 0; $row < count($currencies); $row++) { if ($currencies[$row]['symbol'] == C('DEFAULT_CURRENCIES_SYMBOL')) { $_SESSION['currency'] = $currencies[$row]; } } } //生产一个唯一的session id $this->sessionID = Cookie::get('sessionID'); if (!$this->sessionID) { $this->sessionID = create_session_id(); Cookie::set('sessionID', $this->sessionID); } //读取用户id $auth_cookie = Cookie::get('auth'); if (empty($auth_cookie)) { $this->memberID = 0; } else { $auth = daddslashes(explode("\t", authcode($auth_cookie, 'DECODE', C('AUTHKEY')))); list($member_id, $member_email) = empty($auth) || count($auth) < 2 ? array('', '') : $auth; if (!empty($member_id)) { $this->memberID = $member_id; } } Cookie::set('memberID', $this->memberID); if ($this->memberID) { //读取用户信息 $this->mid = $this->memberID; self::$Model = D("Members"); $this->memberInfo = self::$Model->where("id=" . $this->memberID)->find(); $this->member_Info = $this->memberInfo; self::$Model = D("Shippingaddress"); $this->memberShippingAddress = self::$Model->where("id=" . $this->memberID)->find(); Cookie::set('memberShippingAddress', $this->memberShippingAddress); $this->member_ShippingAddress = $this->memberShippingAddress; /*$this->_365call=" <script type=\"text/javascript\"> //<![CDATA[ var _365call_memberID = \"{$this->memberInfo['email']}\"; // char(20) 账号(会员号) var _365call_clientName= \"{$this->memberInfo['firstname']}{$this->memberInfo['lastname']}\"; // char(50) 用户名(姓名) var _365call_email = \"{$this->memberInfo['email']}\"; // char(50) 邮件地址 var _365call_phone = \"{$this->memberShippingAddress['telphone']}\"; // char(20) 联系电话 var _365call_msn = \"\"; // char(50) MSN var _365call_qq = \"\"; // char(20) QQ var _365call_note = \"{$this->memberShippingAddress['address']}\"; // char(100) 其他 //]]> </script>";*/ } //当前月份 $today = getdate(); $this->month = $today['month']; //总重量 self::$Model = D("Cart"); $this->Total_weight = self::$Model->cart_total_weight($this->sessionID); //购物车商品 $this->cart_list = self::$Model->cart_list($this->sessionID); $this->item_count = itemCount(); $this->total_count = TotalCount(); //会员等级 $this->memberGropuInfo = get_members_group($this->memberID); if (get_members_group($this->memberID)) { $this->isVip = 1; } else { $this->isVip = 0; } /** * bof缓存模板变量 */ //全局模板变量 if (F('Common_Cache') == '') { F('Common_Cache', $this->_Common_Cache()); } $this->assign(F('Common_Cache')); //产品缓存 if (F('Products_Cache') == '') { F('Products_Cache', $this->_Products_Cache()); } //打乱随机显示 $Products_Cache = F('Products_Cache'); //$Products_Cache['FeaturedProducts']=$this->ProModel->rand($Products_Cache['FeaturedProducts']); //$Products_Cache['HotProducts']=$this->ProModel->rand($Products_Cache['HotProducts']); //$Products_Cache['NewProducts']=$this->ProModel->rand($Products_Cache['NewProducts']); //$Products_Cache['SpeProducts']=$this->ProModel->rand($Products_Cache['SpeProducts']); $this->assign($Products_Cache); /** * eof缓存模板变量 */ }
function session($name, $value = '', $operation = '') { static $config = null; /* session设置 */ static $type = null; /* session类型 */ static $db = null; /* session数据库对象 */ static $session_id = ''; /* session数据的id */ static $session_object = array(); /* session数据对象 */ static $initialized = false; /* session是否初始化 */ /* 生成随机的session id */ function create_session_id() { $t = microtime(); $str = $_SERVER['REMOTE_ADDR'] . $t . mt_srand(); return md5($str); } /* 读取配置文件 */ if ($config === null) { $config = config('SESSION'); $type = $config['TYPE']; } switch ($type) { /* 使用系统的session */ case 'system': /* 初始化 */ if (!$initialized) { session_name($config['COOKIE']); session_cache_expire($config['EXPIRE']); session_start(); $initialized = true; } switch ($operation) { /* 销毁session */ case 'destroy': session_unset(); session_destroy(); return true; /* 删除某个值 */ /* 删除某个值 */ case 'delete': if (isset($_SESSION[$name])) { unset($_SESSION[$name]); } return true; } /* 读取及赋值 */ if (is_string($name) && $name !== '') { if ($value === '') { return $_SESSION[$name]; } else { $_SESSION[$name] = $value; } } break; /* 使用数据库方式存储session */ /* 使用数据库方式存储session */ case 'db': /* 初始化数据库 */ if ($db === null) { $db = new Model($config['DB']['tableName'], $config['DB']); } /* 根据几率触发session gc */ if (mt_rand(1, $config['GCDIVER']) === 1) { $db->where(array('last' => array('lt', time() - $config['EXPIRE'])))->delete(); } if (!$initialized) { $session_id = cookie($config['COOKIE']); if (!$session_id) { $session_id = create_session_id(); $db->data(array('key' => $session_id, 'value' => '{}', 'last' => time()))->add(); } $object = $db->where(array('key' => $session_id))->find(); if ($object) { /* 如果发现session超时 */ if ($object['last'] + $config['EXPIRE'] < time()) { $session_id = create_session_id(); $db->data(array('key' => $session_id, 'value' => '{}', 'last' => time()))->add(); $session_object = array(); } else { $session_object = json_decode($object['value'], true); } } cookie($config['COOKIE'], $session_id); } switch ($operation) { case 'destroy': $db->where(array('key' => $session_id))->delete(); $initialized = false; $session_object = array(); cookie($config['COOKIE'], '', time() - 100); return true; case 'delete': if (isset($session_object[$name])) { unset($session_object[$name]); $db->where(array('key' => $session_id))->data(array('value' => json_encode($session_object), 'last' => time()))->update(); } return true; } if (is_string($name) && $name !== '') { if ($value === '') { return $session_object[$name]; } else { $session_object[$name] = $value; $db->where(array('key' => $session_id))->data(array('value' => json_encode($session_object), 'last' => time()))->update(); } } break; case 'cache': /* * @TODO: 完成cache部分 */ break; } }