Exemple #1
0
 /**
  * start a session
  */
 public static function start()
 {
     $params =& $GLOBALS['gJConfig']->sessions;
     // do not start the session if the request is made from the command line or if sessions are disabled in configuration
     if ($GLOBALS['gJCoord']->request instanceof jCmdLineRequest || !$params['start']) {
         return false;
     }
     //make sure that the session cookie is only for the current application
     if (!$params['shared_session']) {
         session_set_cookie_params(0, $GLOBALS['gJConfig']->urlengine['basePath']);
     }
     if ($params['storage'] != '') {
         /* on debian/ubuntu (maybe others), garbage collector launch probability is set to 0
            and replaced by a simple cron job which is not enough for jSession (different path, db storage, ...),
            so we set it to 1 as PHP's default value */
         if (!ini_get('session.gc_probability')) {
             ini_set('session.gc_probability', '1');
         }
         switch ($params['storage']) {
             case 'dao':
                 session_set_save_handler(array(__CLASS__, 'daoOpen'), array(__CLASS__, 'daoClose'), array(__CLASS__, 'daoRead'), array(__CLASS__, 'daoWrite'), array(__CLASS__, 'daoDestroy'), array(__CLASS__, 'daoGarbageCollector'));
                 self::$_params = $params;
                 break;
             case 'files':
                 session_save_path($params['files_path']);
                 break;
         }
     }
     if ($params['name'] != '') {
         #ifnot ENABLE_OPTIMIZED_SOURCE
         if (!preg_match('#^[a-zA-Z0-9]+$#', $params['name'])) {
             // regexp check because session name can only be alpha numeric according to the php documentation
             throw new jException('jelix~errors.jsession.name.invalid');
         }
         #endif
         session_name($params['name']);
     }
     if (isset($params['_class_to_load'])) {
         foreach ($params['_class_to_load'] as $file) {
             require_once $file;
         }
     }
     session_start();
     return true;
 }
Exemple #2
0
 public static function start()
 {
     $params =& jApp::config()->sessions;
     if (jApp::coord()->request instanceof jCmdLineRequest || !$params['start']) {
         return false;
     }
     if (!$params['shared_session']) {
         session_set_cookie_params(0, jApp::config()->urlengine['basePath']);
     }
     if ($params['storage'] != '') {
         if (!ini_get('session.gc_probability')) {
             ini_set('session.gc_probability', '1');
         }
         switch ($params['storage']) {
             case 'dao':
                 session_set_save_handler(array(__CLASS__, 'daoOpen'), array(__CLASS__, 'daoClose'), array(__CLASS__, 'daoRead'), array(__CLASS__, 'daoWrite'), array(__CLASS__, 'daoDestroy'), array(__CLASS__, 'daoGarbageCollector'));
                 self::$_params = $params;
                 break;
             case 'files':
                 session_save_path($params['files_path']);
                 break;
         }
     }
     if ($params['name'] != '') {
         session_name($params['name']);
     }
     if (isset($params['_class_to_load'])) {
         foreach ($params['_class_to_load'] as $file) {
             require_once $file;
         }
     }
     session_start();
     return true;
 }