public static function start($save_path, $session_name) { Session::$sid = session_id(); //This is a core PHP function. Save that a session has been started in the default server log. //error_log('Starting Session ' . $session_name . " ". $this->sid);//DEBUG// /* * Get the userID of the saved session (if exists). * If the query returns no valid rows (ie: this is a NEW session), * $data will be a blank array, thus never tripping the foreach and preserving $this->uid as FALSE. */ $rs = Typeframe::Database()->prepare("SELECT `uid`\r\n FROM #__sessions\r\n WHERE `sid` = ? AND `ip_addr` = ? LIMIT 1"); $rs->execute(Session::$sid, REMOTE_IP); /** * The session is NEW. Create it. */ if ($rs->recordcount() == 0) { $rs2 = Typeframe::Database()->prepare("INSERT INTO #__sessions\r\n (`sid`, `ip_addr`, `uid`, `expires`)\r\n VALUES\r\n (?, ?, ?, ?)"); $rs2->execute(Session::$sid, REMOTE_IP, 0, Session::$ttl + time()); } else { $data = $rs->fetch_array(); Session::$uid = $data['uid']; $rs2 = Typeframe::Database()->prepare("UPDATE #__sessions\r\n SET `expires` = ?\r\n WHERE `sid` = ? AND `ip_addr` = ?"); $rs2->execute(Session::$ttl + time(), Session::$sid, REMOTE_IP); } }
/** * Begins the session. */ public static function start() { session_start(); if (isset($_SESSION[self::$name . '_SID'])) { self::$sid = $_SESSION[self::$name . '_SID']; self::$data = $_SESSION[self::$name . '_DATA']; } else { self::$sid = md5(time()); self::$data = array('lang' => Lang::current(), 'uid' => 0); $_SESSION[self::$name . '_SID'] = self::$sid; $_SESSION[self::$name . '_DATA'] = self::$data; } Lang::load(self::_('lang')); if (self::$data['uid']) { self::$logged = true; } }
/** * 初始化session */ private static function session() { //init session save type if (extension_loaded('memcache') && self::$_conf['SESSION_SAVE_TYPE'] == 'm') { ini_set('session.save_handler', 'memcache'); ini_set('session.save_path', 'tcp://' . self::$_conf['MEM_HOST'] . ':' . self::$_conf['MEM_PORT']); } Session::sid(self::$_conf['S_ID']); Session::name(self::$_conf['S_NAME']); Session::expire(self::$_conf['S_EXPIRE']); session_start(); }