0 - already called session_regenerate_id() * * @var int */ private static $_regenerateIdState = 0; /** * Private list of php's ini values for ext/session * null values will default to the php.ini value, otherwise * the value below will overwrite the default ini value, unless * the user has set an option explicity with setOptions() * * @var array */ private static $_defaultOptions = array( 'save_path' => null, 'name' => null, /* this should be set to a unique value for each application */ 'save_handler' => null, //'auto_start' => null, /* intentionally excluded (see manual) */ 'gc_probability' => null, 'gc_divisor' => null, 'gc_maxlifetime' => null, 'serialize_handler' => null, 'cookie_lifetime' => null, 'cookie_path' => null, 'cookie_domain' => null, 'cookie_secure' => null, 'cookie_httponly' => null, 'use_cookies' => null, 'use_only_cookies' => 'on', 'referer_check' => null, 'entropy_file' => null, 'entropy_length' => null, 'cache_limiter' => null, 'cache_expire' => null, 'use_trans_sid' => null, 'bug_compat_42' => null, 'bug_compat_warn' => null, 'hash_function' => null, 'hash_bits_per_character' => null); /** * List of options pertaining to Zend_Session that can be set by developers * using Zeed_Session::setOptions(). This list intentionally duplicates * the individual declaration of static "class" variables by the same names. * * @var array */ private static $_localOptions = array( 'use_uuid_for_sid' => '_useUUIDForSID'); /** * 是否使用 UUID 作为 Session ID */ private static $_useUUIDForSID = true; /** * 默认设置是否已设置标记 * Whether the default options listed in Zend_Session::$_localOptions have been set * * @var bool */ private static $_defaultOptionsSet = false; /** * @var Zeed_Session_Storage_Interface */ private static $_storager = null; /** * Session Save Handler assignment * * @param Zeed_Session_Storage_Interface $interface * @return void */ public static function setStorager(Zeed_Session_Storage_Interface $storager) { self::$_storager = $storager; session_set_save_handler(array( &$storager, 'open'), array( &$storager, 'close'), array( &$storager, 'read'), array( &$storager, 'write'), array( &$storager, 'destroy'), array( &$storager, 'gc')); } public static function getStorager() { return self::$_storager; } /** * 重新生成 Session ID,这意味了 Session 的数据将初始化 * 建议在 Session 启动后再调用该函数 * * @throws Zeed_Exception * @return void */ public static function regenerateId($deleteOldSession = true) { if (! self::$_sessionStarted) { if (headers_sent($filename, $linenum)) { throw new Zeed_Exception("You must call " . __CLASS__ . '::' . __FUNCTION__ . "() before any output has been sent to the browser; output started in {$filename}/{$linenum}"); } } if (self::$_sessionStarted && self::$_regenerateIdState <= 0) { session_regenerate_id($deleteOldSession); self::$_regenerateIdState = 1; } else { self::$_regenerateIdState = - 1; } } /** * 启动 Session * * @param bool|array $options OPTIONAL Either user supplied options, or flag indicating if start initiated automatically * @throws Zend_Session_Exception * @return void */ public static function start($options = false) { if (self::$_sessionStarted && self::$_destroyed) { throw new Zeed_Exception('The session was explicitly destroyed during this request, attempting to re-start is not allowed.'); } if (self::$_sessionStarted) { return; // already started } $filename = $linenum = null; if (headers_sent($filename, $linenum)) { throw new Zeed_Exception("Session must be started before any output has been sent to the browser;" . " output started in {$filename}/{$linenum}"); } // See http://www.php.net/manual/en/ref.session.php for explanation if (defined('SID')) { throw new Zeed_Exception('session has already been started by session.auto-start or session_start()'); } $startedCleanly = session_start(); self::$_sessionStarted = true; if (self::$_regenerateIdState === - 1) { self::regenerateId(); } } /** * 获取当前 Session ID * session_id() returns the session id for the current session or the empty string ("") * if there is no current session (no current session id exists). * * @return string */ public static function getID() { return session_id(); } /** * Session 设置 * * @param array $userOptions - pass-by-keyword style array of