OneLogin_Saml2_Utils::getSelfHost PHP Method

getSelfHost() public static method

Returns the current host.
public static getSelfHost ( ) : string
return string $currentHost The current host
    public static function getSelfHost()
    {
        $currentHost = self::getRawHost();
        // strip the port
        if (false !== strpos($currentHost, ':')) {
            list($currentHost, $port) = explode(':', $currentHost, 2);
        }
        return $currentHost;
    }

Usage Example

Example #1
0
 /**
  * Tests the getSelfURLhost method of the OneLogin_Saml2_Utils
  *
  * @covers OneLogin_Saml2_Utils::getSelfURLhost
  */
 public function testGetSelfURLhost()
 {
     $hostname = OneLogin_Saml2_Utils::getSelfHost();
     $this->assertEquals("http://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost());
     $_SERVER['SERVER_PORT'] = '80';
     $this->assertEquals("http://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost());
     $_SERVER['SERVER_PORT'] = '81';
     $this->assertEquals("http://{$hostname}:81", OneLogin_Saml2_Utils::getSelfURLhost());
     $_SERVER['SERVER_PORT'] = '443';
     $this->assertEquals("https://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost());
     unset($_SERVER['SERVER_PORT']);
     $_SERVER['HTTPS'] = 'on';
     $this->assertEquals("https://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost());
     $_SERVER['SERVER_PORT'] = '444';
     $this->assertEquals("https://{$hostname}:444", OneLogin_Saml2_Utils::getSelfURLhost());
     $_SERVER['SERVER_PORT'] = '443';
     $_SERVER['REQUEST_URI'] = '/onelogin';
     $this->assertEquals("https://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost());
     $_SERVER['REQUEST_URI'] = 'https://$hostname/onelogin/sso';
     $this->assertEquals("https://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost());
 }
All Usage Examples Of OneLogin_Saml2_Utils::getSelfHost