Example #1
0
 /**
  * Load the basics of the current environment
  *
  * The purpose of this method is to consolidate all the various environment information into one
  * array under a set of common names, thereby removing the tedium of figuring out which superglobal 
  * and key combination contain the requested information each time it is needed.
  * 
  * @return void
  */
 protected function _LoadEnvironment()
 {
     $this->_EnvironmentElement('ConfigWebRoot', Gdn::Config('Garden.WebRoot'));
     $this->_EnvironmentElement('ConfigStrips', Gdn::Config('Garden.StripWebRoot', FALSE));
     $this->RequestHost(isset($_SERVER['HTTP_HOST']) ? ArrayValue('HTTP_HOST', $_SERVER) : ArrayValue('SERVER_NAME', $_SERVER));
     $this->RequestMethod(isset($_SERVER['REQUEST_METHOD']) ? ArrayValue('REQUEST_METHOD', $_SERVER) : 'CONSOLE');
     $this->RequestScheme(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http');
     if (is_array($_GET)) {
         $Get = FALSE;
         if ($Get === FALSE) {
             $Get =& $_GET;
         }
         if (!is_array($Get)) {
             $Original = array();
             parse_str($Get, $Original);
             SafeParseStr($Get, $Get, $Original);
         }
         if (isset($Get['p'])) {
             $Path = $Get['p'];
             unset($_GET['p']);
         } else {
             $Path = '';
         }
         $this->RequestURI($Path);
     }
     $PossibleScriptNames = array();
     if (isset($_SERVER['SCRIPT_NAME'])) {
         $PossibleScriptNames[] = $_SERVER['SCRIPT_NAME'];
     }
     if (isset($_ENV['SCRIPT_NAME'])) {
         $PossibleScriptNames[] = $_ENV['SCRIPT_NAME'];
     }
     if (PHP_SAPI === 'cgi' && isset($_ENV['SCRIPT_URL'])) {
         $PossibleScriptNames[] = $_ENV['SCRIPT_URL'];
     }
     if (isset($_SERVER['SCRIPT_FILENAME'])) {
         $PossibleScriptNames[] = $_SERVER['SCRIPT_FILENAME'];
     }
     if (isset($_SERVER['ORIG_SCRIPT_NAME'])) {
         $PossibleScriptNames[] = $_SERVER['ORIG_SCRIPT_NAME'];
     }
     $this->RequestFolder('');
     $TrimURI = trim($this->RequestURI(), '/');
     foreach ($PossibleScriptNames as $ScriptName) {
         $Script = basename($ScriptName);
         $this->RequestScript($Script);
         $Folder = substr($ScriptName, 0, 0 - strlen($Script));
         $TrimFolder = trim($Folder, '/');
         $TrimScript = trim($Script, '/');
         if (isset($_SERVER['DOCUMENT_ROOT'])) {
             $DocumentRoot = $_SERVER['DOCUMENT_ROOT'];
         } else {
             $AbsolutePath = str_replace("\\", "/", realpath($Script));
             $DocumentRoot = substr($AbsolutePath, 0, strpos($AbsolutePath, $ScriptName));
         }
         if (!$DocumentRoot) {
             continue;
         }
         $TrimRoot = rtrim($DocumentRoot);
         $RealFolder = str_replace($TrimRoot, '', $Folder);
         if (!empty($RealFolder)) {
             $this->RequestFolder(ltrim($RealFolder, '/'));
             break;
         }
     }
 }
Example #2
0
 /**
  * Load the basics of the current environment
  *
  * The purpose of this method is to consolidate all the various environment information into one
  * array under a set of common names, thereby removing the tedium of figuring out which superglobal 
  * and key combination contain the requested information each time it is needed.
  * 
  * @return void
  */
 protected function _LoadEnvironment()
 {
     $this->_EnvironmentElement('ConfigWebRoot', Gdn::Config('Garden.WebRoot'));
     $this->_EnvironmentElement('ConfigStripUrls', Gdn::Config('Garden.StripWebRoot', FALSE));
     $this->RequestHost(isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? GetValue('HTTP_X_FORWARDED_HOST', $_SERVER) : (isset($_SERVER['HTTP_HOST']) ? GetValue('HTTP_HOST', $_SERVER) : GetValue('SERVER_NAME', $_SERVER)));
     $this->RequestMethod(isset($_SERVER['REQUEST_METHOD']) ? GetValue('REQUEST_METHOD', $_SERVER) : 'CONSOLE');
     // Request IP
     // Loadbalancers
     $IP = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? GetValue('HTTP_X_FORWARDED_FOR', $_SERVER) : $_SERVER['REMOTE_ADDR'];
     if (strpos($IP, ',') !== FALSE) {
         $IP = substr($IP, 0, strpos($IP, ','));
     }
     // Varnish
     $OriginalIP = GetValue('HTTP_X_ORIGINALLY_FORWARDED_FOR', $_SERVER, NULL);
     if (!is_null($OriginalIP)) {
         $IP = $OriginalIP;
     }
     $this->RequestAddress($IP);
     // Request Scheme
     $Scheme = 'http';
     // Webserver-originated SSL
     if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
         $Scheme = 'https';
     }
     // Loadbalancer-originated (and terminated) SSL
     if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') {
         $Scheme = 'https';
     }
     // Varnish
     $OriginalProto = GetValue('HTTP_X_ORIGINALLY_FORWARDED_PROTO', $_SERVER, NULL);
     if (!is_null($OriginalProto)) {
         $Scheme = $OriginalProto;
     }
     $this->RequestScheme($Scheme);
     if (is_array($_GET)) {
         $Get = FALSE;
         if ($Get === FALSE) {
             $Get =& $_GET;
         }
         if (!is_array($Get)) {
             $Original = array();
             parse_str($Get, $Original);
             SafeParseStr($Get, $Get, $Original);
         }
         if (isset($Get['p'])) {
             $Path = $Get['p'];
             unset($_GET['p']);
         } else {
             $Path = '';
         }
         $this->RequestURI($Path);
     }
     $PossibleScriptNames = array();
     if (isset($_SERVER['SCRIPT_NAME'])) {
         $PossibleScriptNames[] = $_SERVER['SCRIPT_NAME'];
     }
     if (isset($_ENV['SCRIPT_NAME'])) {
         $PossibleScriptNames[] = $_ENV['SCRIPT_NAME'];
     }
     if (PHP_SAPI === 'cgi' && isset($_ENV['SCRIPT_URL'])) {
         $PossibleScriptNames[] = $_ENV['SCRIPT_URL'];
     }
     if (isset($_SERVER['SCRIPT_FILENAME'])) {
         $PossibleScriptNames[] = $_SERVER['SCRIPT_FILENAME'];
     }
     if (isset($_SERVER['ORIG_SCRIPT_NAME'])) {
         $PossibleScriptNames[] = $_SERVER['ORIG_SCRIPT_NAME'];
     }
     $this->RequestFolder('');
     $TrimURI = trim($this->RequestURI(), '/');
     foreach ($PossibleScriptNames as $ScriptName) {
         $Script = basename($ScriptName);
         $this->RequestScript($Script);
         $Folder = substr($ScriptName, 0, 0 - strlen($Script));
         $TrimFolder = trim($Folder, '/');
         $TrimScript = trim($Script, '/');
         if (isset($_SERVER['DOCUMENT_ROOT'])) {
             $DocumentRoot = $_SERVER['DOCUMENT_ROOT'];
         } else {
             $AbsolutePath = str_replace("\\", "/", realpath($Script));
             $DocumentRoot = substr($AbsolutePath, 0, strpos($AbsolutePath, $ScriptName));
         }
         if (!$DocumentRoot) {
             continue;
         }
         $TrimRoot = rtrim($DocumentRoot);
         $RealFolder = str_replace($TrimRoot, '', $Folder);
         if (!empty($RealFolder)) {
             $this->RequestFolder(ltrim($RealFolder, '/'));
             break;
         }
     }
 }