コード例 #1
0
ファイル: SESSION.php プロジェクト: nicolas-grekas/Patchwork
 static function __init()
 {
     self::$savePath = $CONFIG['session.save_path'];
     self::$cookiePath = $CONFIG['session.cookie_path'];
     self::$cookieDomain = $CONFIG['session.cookie_domain'];
     $CONFIG['session.auth_vars'] && (self::$authVars = array_merge(self::$authVars, $CONFIG['session.auth_vars']));
     $CONFIG['session.group_vars'] && (self::$groupVars = array_merge(self::$groupVars, $CONFIG['session.group_vars']));
     self::$authVars = array_flip(self::$authVars);
     self::$groupVars = array_flip(self::$groupVars);
     if (self::$maxIdleTime < 1 && self::$maxLifeTime < 1) {
         user_error('At least one of the SESSION::$max*Time variables must be strictly positive.');
     }
     if (mt_rand(1, self::$gcProbabilityDenominator) <= self::$gcProbabilityNumerator) {
         $adapter = new self('0lastGC');
         $i = $adapter->read();
         $j = max(self::$maxIdleTime, self::$maxLifeTime);
         if ($j && $_SERVER['REQUEST_TIME'] - $i > $j) {
             $adapter->write($_SERVER['REQUEST_TIME']);
             register_shutdown_function(array(__CLASS__, 'gc'), $j);
         }
         unset($adapter);
     }
     if (isset($_COOKIE['SID'])) {
         self::setSID($_COOKIE['SID']);
         self::$adapter = new self(self::$SID);
         $i = self::$adapter->read();
     } else {
         $i = false;
     }
     if ($i) {
         $i = unserialize($i);
         self::$lastseen = $i[0];
         self::$birthtime = $i[1];
         if (self::$maxIdleTime && $_SERVER['REQUEST_TIME'] - self::$lastseen > self::$maxIdleTime) {
             // Session has idled
             self::onIdle();
             self::$isIdled = true;
         } else {
             if (self::$maxLifeTime && $_SERVER['REQUEST_TIME'] - self::$birthtime > self::$maxLifeTime) {
                 // Session has expired
                 self::onExpire();
             } else {
                 self::$DATA =& $i[2];
             }
         }
         if (isset($_SERVER['HTTPS']) && (!isset($_COOKIE['SSL']) || $i[3] != $_COOKIE['SSL'])) {
             self::regenerateId(true);
         } else {
             self::$sslid = $i[3];
             if ('-' == self::$sslid[0] && isset($_SERVER['HTTPS'])) {
                 self::$sslid = p::strongId();
                 setcookie('SSL', self::$sslid, 0, self::$cookiePath, self::$cookieDomain, true, true);
                 unset($_SERVER['HTTP_IF_NONE_MATCH'], $_SERVER['HTTP_IF_MODIFIED_SINCE']);
             }
         }
     } else {
         self::regenerateId(true);
     }
 }