예제 #1
0
 /**
  * Starts a new session
  *
  * <code>
  * 
  * s::start();
  * // do whatever you want with the session now
  * 
  * </code>
  * 
  */
 public static function start()
 {
     if (session_status() === PHP_SESSION_ACTIVE) {
         return true;
     }
     // store the session name
     static::$cookie += array('lifetime' => 0, 'path' => ini_get('session.cookie_path'), 'domain' => ini_get('session.cookie_domain'), 'secure' => r::secure(), 'httponly' => true);
     // set the custom session name
     session_name(static::$name);
     // make sure to use cookies only
     ini_set('session.use_cookies', 1);
     ini_set('session.use_only_cookies', 1);
     // try to start the session
     if (!session_start()) {
         return false;
     }
     if (!setcookie(static::$name, session_id(), cookie::lifetime(static::$cookie['lifetime']), static::$cookie['path'], static::$cookie['domain'], static::$cookie['secure'], static::$cookie['httponly'])) {
         return false;
     }
     // mark it as started
     static::$started = true;
     // check if the session is still valid
     if (!static::check()) {
         return static::destroy();
     }
     return true;
 }