Пример #1
0
 /**
  * Sets the minimum length of a session - PHP might not clean up the session data right away once this timespan has elapsed
  * 
  * Please be sure to set a custom session path via ::setPath() to ensure
  * another site on the server does not garbage collect the session files
  * from this site!
  * 
  * Both of the timespan can accept either a integer timespan in seconds,
  * or an english description of a timespan (e.g. `'30 minutes'`, `'1 hour'`,
  * `'1 day 2 hours'`).
  * 
  * @param  string|integer $normal_timespan      The normal, session-based cookie, length for the session
  * @param  string|integer $persistent_timespan  The persistent, timed-based cookie, length for the session - this is enabled by calling ::enabledPersistence() during login
  * @return void
  */
 public static function setLength($normal_timespan, $persistent_timespan = NULL)
 {
     if (self::$open || isset($_SESSION)) {
         throw new fProgrammerException('%1$s must be called before any of %2$s, %3$s, %4$s, %5$s, %6$s, %7$s or %8$s', __CLASS__ . '::setLength()', __CLASS__ . '::add()', __CLASS__ . '::clear()', __CLASS__ . '::enablePersistence()', __CLASS__ . '::get()', __CLASS__ . '::open()', __CLASS__ . '::set()', 'session_start()');
     }
     $seconds = !is_numeric($normal_timespan) ? strtotime($normal_timespan) - time() : $normal_timespan;
     self::$normal_timespan = $seconds;
     if ($persistent_timespan) {
         $seconds = !is_numeric($persistent_timespan) ? strtotime($persistent_timespan) - time() : $persistent_timespan;
         self::$persistent_timespan = $seconds;
     }
     ini_set('session.gc_maxlifetime', $seconds);
 }