/** * 返回单例模式 */ public static function getInstance() { // CLI模式直接使用Yaf原生自带的Session机制($_SESSION原理一致) if (!APPLICATION_IS_CLI) { return \Yaf\Session::getInstance(); } // 查看全局空间是否存在实例 if (!is_null(self::$_instance)) { return self::$_instance; } // 开启模拟Session机制,并注册全局空间 self::$_instance = new self(); self::$_instance->start(); return self::$_instance; }
/** * * open the session * @param string $save_path * @param string $session_name */ public static function open($save_path, $session_name) { self::$_db = self::getMemcache(); self::$_ivSize = mcrypt_get_iv_size(self::CIPHER, self::CIPHER_MODE); self::$_keyName = 'y' . $session_name; if (empty($_COOKIE[self::$_keyName])) { $keyLength = mcrypt_get_key_size(self::CIPHER, self::CIPHER_MODE); self::$_key = self::_randKey($keyLength); $cookie_param = session_get_cookie_params(); setcookie(self::$_keyName, base64_encode(self::$_key), $cookie_param['lifetime'], $cookie_param['path'], $cookie_param['domain'], $cookie_param['secure'], $cookie_param['httponly']); } else { self::$_key = base64_decode($_COOKIE[self::$_keyName]); } return true; }
public static function initSession(array $config = array()) { if (true === self::$sessionInited) { return true; } $defaultConfig = Api::_()->getConfig(); $sessionNamespace = 'Eva'; if (isset($defaultConfig['session'])) { $config = array_merge($defaultConfig['session'], $config); if (isset($defaultConfig['session']['namespace']) && $defaultConfig['session']['namespace']) { $sessionNamespace = $defaultConfig['session']['namespace']; } } $config = new SessionConfig($config); self::$sessionManager = $manager = new SessionManager($config); self::$sessionContainer = new Container($sessionNamespace, $manager); return self::$sessionInited = true; }
/** * 打开Session * @param String $pSavePath * @param String $pSessName * @return Bool TRUE/FALSE */ public function open($save_path = '', $sess_name = '') { self::$cache_prefix = $save_path . '_' . $sess_name; return true; }
/** * @return Session */ private static function _GetInstance(){ if(self::$Instance === null){ ini_set('session.hash_bits_per_character', 5); ini_set('session.hash_function', 1); if(!defined('SESSION_COOKIE_NAME')){ define('SESSION_COOKIE_NAME', 'CorePlusSession'); } session_name(SESSION_COOKIE_NAME); // Allow a config-set cookie domain. This is required for xsite sessions in multimode. if(defined('SESSION_COOKIE_DOMAIN') && SESSION_COOKIE_DOMAIN){ // A valid session name is required for xsite sessions to work. (not sure why) session_set_cookie_params(0, '/', SESSION_COOKIE_DOMAIN); } self::$Instance = new Session(); //$session = new Session(); session_set_save_handler(self::$Instance, true); session_start(); } return self::$Instance; }