Example #1
0
 /**
  * Sets a custom session handler up, if there is one.
  * If the global variable 'session_cache_limiter' is defined, its value
  * will override the cache limiter setting found in the configuration
  * file.
  */
 function setupSessionHandler()
 {
     global $conf;
     ini_set('url_rewriter.tags', 0);
     if (!empty($conf['session']['use_only_cookies'])) {
         ini_set('session.use_only_cookies', 1);
         if (!empty($conf['cookie']['domain']) && strpos($conf['server']['name'], '.') === false) {
             Horde::fatal('Session cookies will not work without a FQDN and with a non-empty cookie domain. Either use a fully qualified domain name like "http://www.example.com" instead of "http://example" only, or set the cookie domain in the Horde configuration to an empty value, or enable non-cookie (url-based) sessions in the Horde configuration.', __FILE__, __LINE__);
         }
     }
     session_set_cookie_params($conf['session']['timeout'], $conf['cookie']['path'], $conf['cookie']['domain'], $conf['use_ssl'] == 1 ? 1 : 0);
     session_cache_limiter(Util::nonInputVar('session_cache_limiter', $conf['session']['cache_limiter']));
     session_name(urlencode($conf['session']['name']));
     $type = !empty($conf['sessionhandler']['type']) ? $conf['sessionhandler']['type'] : 'none';
     if ($type == 'external') {
         $calls = $conf['sessionhandler']['params'];
         session_set_save_handler($calls['open'], $calls['close'], $calls['read'], $calls['write'], $calls['destroy'], $calls['gc']);
     } elseif ($type != 'none') {
         require_once 'Horde/SessionHandler.php';
         $sh =& SessionHandler::singleton($conf['sessionhandler']['type'], array_merge(Horde::getDriverConfig('sessionhandler', $conf['sessionhandler']['type']), array('memcache' => !empty($conf['sessionhandler']['memcache']))));
         if (is_a($sh, 'PEAR_Error')) {
             Horde::fatal(PEAR::raiseError('Horde is unable to correctly start the custom session handler.'), __FILE__, __LINE__, false);
         } else {
             ini_set('session.save_handler', 'user');
             session_set_save_handler(array(&$sh, 'open'), array(&$sh, 'close'), array(&$sh, 'read'), array(&$sh, 'write'), array(&$sh, 'destroy'), array(&$sh, 'gc'));
         }
     }
 }