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(); } }