/**
  * Gets the base URI requested by a client.
  *
  * @return string
  */
 public static function getBaseURI()
 {
     if (Stagehand_HTTP_ServerEnv::isSecure()) {
         $scheme = 'https';
     } else {
         $scheme = 'http';
     }
     if (Stagehand_HTTP_ServerEnv::isRunningOnStandardPort()) {
         $port = '';
     } else {
         $port = ':' . $_SERVER['SERVER_PORT'];
     }
     return $scheme . '://' . $_SERVER['SERVER_NAME'] . $port;
 }
Esempio n. 2
0
 /**
  * Gets the absolute URI.
  * The standard port of the URI scheme is set when using reverse-proxy.
  *
  * @param string $scheme The scheme for the URI. The scheme MUST be one of:
  *                       https, http, or pass (default).
  * @return string
  */
 public function getURI($scheme = 'pass')
 {
     if (is_null($this->_url)) {
         $this->initialize();
     }
     if ($this->_isExternal) {
         return $this->_url->getURL();
     }
     if (!$this->_isRedirection && Stagehand_HTTP_ServerEnv::usingProxy() && array_key_exists('HTTP_X_FORWARDED_SERVER', $_SERVER)) {
         if ($this->_url->getHost() != $_SERVER['HTTP_X_FORWARDED_SERVER']) {
             $this->_url->setHost($_SERVER['HTTP_X_FORWARDED_SERVER']);
         }
     } else {
         $this->_url->setHost($_SERVER['SERVER_NAME']);
         $this->_url->setPort($_SERVER['SERVER_PORT']);
         $this->_url->setPath($this->context->removeProxyPath($this->_url->getPath()));
     }
     $url = clone $this->_url;
     if (!in_array($scheme, array('https', 'http', 'pass'))) {
         $scheme = 'pass';
     }
     if ($scheme == 'pass') {
         $scheme = $this->_url->getScheme();
         $port = $this->_url->getPort();
     }
     if ($scheme == 'https') {
         $url->setScheme('https');
         $port = 443;
     } elseif ($scheme == 'http') {
         $url->setScheme('http');
         $port = 80;
     } else {
         $url->setScheme(Stagehand_HTTP_ServerEnv::isSecure() ? 'https' : 'http');
     }
     if (Stagehand_HTTP_ServerEnv::usingProxy() && !$this->_isRedirection || Stagehand_HTTP_ServerEnv::isRunningOnStandardPort()) {
         $url->setPort($port);
     }
     return $url->getNormalizedURL();
 }