Esempio n. 1
0
 /**
  * Create a new session.
  *
  * @return  void
  */
 public function create()
 {
     $cookie_config = Core::config('cookie');
     $_SESSION = array();
     switch (Session::$config['type']) {
         case 'auto':
             $sid = HttpIO::REQUEST($this->session_name);
             break;
         case 'url':
             $sid = HttpIO::GET($this->session_name);
             break;
         default:
             $sid = HttpIO::COOKIE($this->session_name);
             break;
     }
     if (!$sid || !Session::check_session_id($sid)) {
         $sid = Session::create_session_id();
         if (Session::$config['type'] != 'url') {
             # 将session存入cookie
             Core::cookie()->set($this->session_name, $sid, !Session::$config['httponly'] && Session::$config['expiration'] > 0 ? Session::$config['expiration'] : null, $cookie_config['path'], $cookie_config['domain'], $cookie_config['secure'], Session::$config['httponly']);
         }
     }
     # 添加URL处理自动追加SESSION ID参数
     if (Session::$config['type'] == 'url') {
         Core::add_url_args(Session::$config['name'], $sid);
     }
     # 调试模式设置Session模式,避免开启缓存模式时获取不到Session
     if (IS_DEBUG) {
         $this->driver()->session_mode(true);
     }
     $_SESSION = $this->driver()->get($sid);
     if (IS_DEBUG) {
         $this->driver()->session_mode(false);
     }
     if (!is_array($_SESSION)) {
         $_SESSION = array();
     }
     # 将获取的值序列化MD5值
     Session_Driver_Cache::$OLD_SESSION_MD5 = md5(serialize($_SESSION));
     # 当前session id
     Session_Driver_Cache::$Session_ID = $sid;
 }
Esempio n. 2
0
 /**
  * 创建Session
  *
  * @return  void
  */
 public function create()
 {
     session_name(Session::$config['name']);
     $this->destroy();
     $cookie_config = Core::config('cookie');
     # 这里对IP+非80端口的需要特殊处理下,经试验,当这种情况下,设置session id的cookie的话会失败
     if (preg_match('#^([0-9]+.[0-9]+.[0-9]+.[0-9]+):[0-9]+$#', $cookie_config['domain'], $m)) {
         # IP:PORT 方式
         $cookie_config['domain'] = $m[1];
     }
     $s_name = session_name();
     switch (Session::$config['type']) {
         case 'auto':
             $sid = HttpIO::REQUEST($s_name);
             break;
         case 'url':
             $sid = HttpIO::GET($s_name);
             break;
         default:
             $sid = HttpIO::COOKIE($s_name);
             break;
     }
     if (!$sid || !Session::check_session_id($sid)) {
         # 如果检验的Session ID不合法,则重新生成一个
         session_id(Session::create_session_id());
     } else {
         session_id($sid);
     }
     # Session ID 通过uri传递
     if (Session::$config['type'] == 'url') {
         @ini_set('session.use_only_cookies', 0);
     } else {
         session_set_cookie_params(Session::$config['httponly'] ? 0 : (int) Session::$config['expiration'], $cookie_config['path'], $cookie_config['domain'], $cookie_config['secure'], Session::$config['httponly']);
     }
     session_start();
 }