public function __construct($vars = null) { // This part only needs to be run once if (null === Session::$instance) { // Load config Session::$config = Core::config('session'); if (!isset(Session::$config['check_string']) || !Session::$config['check_string']) { Session::$config['check_string'] = '&$@de23#$%@.d3l-3=!#1'; } if (!isset(Session::$config['name']) || !preg_match('#^(?=.*[a-z])[a-z0-9_]++$#iD', Session::$config['name'])) { // Name the session, this will also be the name of the cookie Session::$config['name'] = 'PHPSESSINID'; } if (IS_DEBUG) { $time = microtime(1); $is_debug = (bool) Core::debug()->profiler()->is_open(); if ($is_debug) { Core::debug()->profiler()->start('Core', 'Session StartTime'); } } if (isset(Session::$config['driver']) && class_exists('Session_Driver_' . Session::$config['driver'], true)) { $driver_name = 'Session_Driver_' . Session::$config['driver']; if (isset(Session::$config['driver_config'])) { Session::$driver = new $driver_name(Session::$config['driver_config']); } else { Session::$driver = new $driver_name(); } } else { Session::$driver = new Session_Driver_Default(); } if (!isset(Session::$config['type']) || Session::$config['type'] != 'url') { Session::$config['type'] = 'cookie'; } if (IS_DEBUG) { if ($is_debug) { Core::debug()->profiler()->stop(); } # 输出Session启动使用时间 Core::debug()->info(microtime(1) - $time, 'Session start use time'); } if ($vars) { $this->set($vars); } if (!isset($_SESSION['_flash_session_'])) { $_SESSION['_flash_session_'] = array(); } Session::$flash =& $_SESSION['_flash_session_']; # 清理Flash Session $this->expire_flash(); $_SESSION['SID'] = Session::$driver->session_id(); # 确保关闭前执行保存 Core::register_shutdown_function(array('Session', 'write_close')); Session::$instance = $this; # 加载用户数据 Session::load_member_data(); } }
/** * On first session instance creation, sets up the driver and creates session. */ public function __construct($vars = null) { // This part only needs to be run once if (Session::$instance === null) { // Load config Session::$config = Core::config('session'); if (!isset(Session::$config['name']) || !preg_match('#^(?=.*[a-z])[a-z0-9_]++$#iD', Session::$config['name'])) { // Name the session, this will also be the name of the cookie Session::$config['name'] = 'PHPSESSINID'; } if (isset(Session::$config['driver']) && class_exists('Session_Driver_' . Session::$config['driver'], true)) { $driver_name = 'Session_Driver_' . Session::$config['driver']; if (isset(Session::$config['driver_config'])) { $this->driver = new $driver_name(Session::$config['driver_config']); } else { $this->driver = new $driver_name(); } } else { $this->driver = new Session_Driver_Default(); } if ($vars) { // Set the new data $this->set($vars); } if (!isset($_SESSION['_flash_session_'])) { $_SESSION['_flash_session_'] = array(); } Session::$flash =& $_SESSION['_flash_session_']; # 清理Flash Session $this->expire_flash(); $_SESSION['SID'] = $this->driver->session_id(); if (!isset($_SESSION['_last_actived_time_']) || TIME - 600 > $_SESSION['_last_actived_time_']) { # 更新最后活动时间 10分钟更新一次 $_SESSION['_last_actived_time_'] = TIME; } # 确保关闭前执行保存 Core::register_shutdown_function(array('Session', 'write_close')); Session::$instance = $this; if (null === Session::$member && isset($_SESSION['member_id']) && $_SESSION['member_id'] > 0) { $orm_member = new ORM_Admin_Member_Finder(); Session::$member = $orm_member->where('id', $_SESSION['member_id'])->find(null, true)->current(); } } }
public function __construct($vars = null) { // This part only needs to be run once if (Session::$instance === null) { // Load config Session::$config = Core::config('session'); if (!isset(Session::$config['name']) || !preg_match('#^(?=.*[a-z])[a-z0-9_]++$#iD', Session::$config['name'])) { // Name the session, this will also be the name of the cookie Session::$config['name'] = 'PHPSESSINID'; } if (isset(Session::$config['driver']) && class_exists('Session_Driver_' . Session::$config['driver'], true)) { $driver_name = 'Session_Driver_' . Session::$config['driver']; if (isset(Session::$config['driver_config'])) { $this->driver = new $driver_name(Session::$config['driver_config']); } else { $this->driver = new $driver_name(); } } else { $this->driver = new Session_Driver_Default(); } if ($vars) { // Set the new data $this->set($vars); } if (!isset($_SESSION['_flash_session_'])) { $_SESSION['_flash_session_'] = array(); } Session::$flash =& $_SESSION['_flash_session_']; # 清理Flash Session $this->expire_flash(); $_SESSION['SID'] = $this->driver->session_id(); # 确保关闭前执行保存 Core::register_shutdown_function(array('Session', 'write_close')); Session::$instance = $this; if (null === Session::$member && isset($_SESSION['member'])) { Session::$member = new Member($_SESSION['member']); } } }