Example #1
2
 public static function start($lifetime = 0, $path = '/', $domain = NULL)
 {
     if (!self::$_initialized) {
         if (!is_object(Symphony::Database()) || !Symphony::Database()->connected()) {
             return false;
         }
         $cache = Cache::instance()->read('_session_config');
         if (is_null($cache) || $cache === false) {
             self::create();
             Cache::instance()->write('_session_config', true);
         }
         if (!session_id()) {
             ini_set('session.save_handler', 'user');
             ini_set('session.gc_maxlifetime', $lifetime);
             ini_set('session.gc_probability', '1');
             ini_set('session.gc_divisor', '3');
         }
         session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc'));
         session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), false, false);
         if (strlen(session_id()) == 0) {
             if (headers_sent()) {
                 throw new Exception('Headers already sent. Cannot start session.');
             }
             session_start();
         }
         self::$_initialized = true;
     }
     return session_id();
 }
Example #2
0
 public static function start($lifetime = 0, $path = '/', $domain = NULL)
 {
     if (!self::$_initialized) {
         if (!is_object(Symphony::Database()) || !Symphony::Database()->isConnected()) {
             return false;
         }
         self::$_cache = new Cacheable(Symphony::Database());
         $installed = self::$_cache->check('_session_config');
         if (!$installed) {
             if (!self::createTable()) {
                 return false;
             }
             self::$_cache->write('_session_config', true);
         }
         ini_set('session.save_handler', 'user');
         ini_set('session.gc_maxlifetime', $lifetime);
         session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc'));
         session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), false, false);
         if (strlen(session_id()) == 0) {
             if (headers_sent()) {
                 throw new Exception('Headers already sent. Cannot start session.');
             }
             session_start();
         }
         self::$_initialized = true;
     }
     return session_id();
 }
 /**
  * Starts a Session object, only if one doesn't already exist. This function maps
  * the Session Handler functions to this classes methods by reading the default
  * information from the PHP ini file.
  *
  * @link http://php.net/manual/en/function.session-set-save-handler.php
  * @link http://php.net/manual/en/function.session-set-cookie-params.php
  * @param integer $lifetime
  *  How long a Session is valid for, by default this is 0, which means it
  *  never expires
  * @param string $path
  *  The path the cookie is valid for on the domain
  * @param string $domain
  *  The domain this cookie is valid for
  * @param boolean $httpOnly
  *  Whether this cookie can be read by Javascript. By default the cookie
  *  cannot be read by Javascript
  * @param boolean $secure
  *  Whether this cookie should only be sent on secure servers. By default this is
  *  false, which means the cookie can be sent over HTTP and HTTPS
  * @throws Exception
  * @return string|boolean
  *  Returns the Session ID on success, or false on error.
  */
 public static function start($lifetime = 0, $path = '/', $domain = null, $httpOnly = true, $secure = false)
 {
     if (!self::$_initialized) {
         if (!is_object(Symphony::Database()) || !Symphony::Database()->isConnected()) {
             return false;
         }
         if (session_id() == '') {
             ini_set('session.save_handler', 'user');
             ini_set('session.gc_maxlifetime', $lifetime);
             ini_set('session.gc_probability', '1');
             ini_set('session.gc_divisor', Symphony::Configuration()->get('session_gc_divisor', 'symphony'));
         }
         session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc'));
         session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), $secure, $httpOnly);
         session_cache_limiter('');
         if (session_id() == '') {
             if (headers_sent()) {
                 throw new Exception('Headers already sent. Cannot start session.');
             }
             register_shutdown_function('session_write_close');
             session_start();
         }
         self::$_initialized = true;
     }
     return session_id();
 }
 public static function start($lifetime = 0, $path = '/', $domain = NULL)
 {
     if (!self::$_initialized) {
         ## Crude method of determining if we're in the admin or frontend
         if (class_exists('Frontend')) {
             self::$_db =& Frontend::instance()->Database;
         } elseif (class_exists('Administration')) {
             self::$_db =& Administration::instance()->Database;
         } else {
             return false;
         }
         if (!is_object(self::$_db) || !self::$_db->isConnected()) {
             return false;
         }
         self::$_cache = new Cacheable(self::$_db);
         $installed = self::$_cache->check('_session_config');
         if (!$installed) {
             if (!self::createTable()) {
                 return false;
             }
             self::$_cache->write('_session_config', true);
         }
         ini_set('session.save_handler', 'user');
         session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc'));
         session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), false, false);
         self::$_initialized = true;
         if (session_id() == '') {
             session_start();
         }
     }
     return session_id();
 }