Example #1
0
 /**
  * sets up the session storage method and starts the session
  * 
  * note: if database storage is used then session_write_close() must be used
  * at the end of every page to ensure the session is written to
  * 
  * @param string $tableName if $tableName is passed then database storage is used
  * @return void
  */
 public static function init($tableName = '')
 {
     // are we using database storage?
     if ($tableName) {
         self::$tableName = $tableName;
         // Register session handler callbacks
         session_set_save_handler(array('Session', "open"), array('Session', "close"), array('Session', "read"), array('Session', "write"), array('Session', "destroy"), array('Session', "gc"));
     }
     // read the maxlifetime setting from PHP
     self::$lifetime = get_cfg_var("session.gc_maxlifetime");
     $configSessionShare = Config::get_optional('session_share');
     // default to only share sessions with current server name
     $sessionShare = !empty($configSessionShare) ? $configSessionShare : SERVER_NAME;
     session_set_cookie_params(self::$lifetime, '/', $sessionShare);
     if (Config::get_optional('session_path')) {
         $sessionPath = Config::get_optional('session_path');
         session_save_path($sessionPath);
     }
     session_start();
 }