SimpleSAML\Utils\HTTP::getSelfHostWithNonStandardPort PHP Method

getSelfHostWithNonStandardPort() public static method

E.g. www.example.com:8080
Author: Andreas Solberg, UNINETT AS ([email protected])
Author: Olav Morken, UNINETT AS ([email protected])
public static getSelfHostWithNonStandardPort ( ) : string
return string The current host, followed by a colon and the port number, in case the port is not standard for the protocol.
    public static function getSelfHostWithNonStandardPort()
    {
        $url = self::getBaseURL();
        $start = strpos($url, '://') + 3;
        $length = strcspn($url, '/', $start);
        return substr($url, $start, $length);
    }

Usage Example

Example #1
0
 /**
  * Test SimpleSAML\Utils\HTTP::getSelfHostWithPort(), with and without custom port.
  */
 public function testGetSelfHostWithPort()
 {
     \SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => ''), '[ARRAY]', 'simplesaml');
     // standard port for HTTP
     $_SERVER['SERVER_PORT'] = '80';
     $this->assertEquals('localhost', HTTP::getSelfHostWithNonStandardPort());
     // non-standard port
     $_SERVER['SERVER_PORT'] = '3030';
     $this->assertEquals('localhost:3030', HTTP::getSelfHostWithNonStandardPort());
     // standard port for HTTPS
     $_SERVER['HTTPS'] = 'on';
     $_SERVER['SERVER_PORT'] = '443';
     $this->assertEquals('localhost', HTTP::getSelfHostWithNonStandardPort());
 }
All Usage Examples Of SimpleSAML\Utils\HTTP::getSelfHostWithNonStandardPort