Http\Request::getHttpHost

public getHttpHost ()

Gets host name used by the request. Request::getHttpHost trying to find host name in following order: - $_SERVER[‘HTTP_HOST’] - $_SERVER[‘SERVER_NAME’] - $_SERVER[‘SERVER_ADDR’] Optionally Request::getHttpHost validates and clean host name. The Request::$_strictHostCheck can be used to validate host name. Note: validation and cleaning have a negative performance impact because they use regular expressions.

use Phalcon\Http\Request;

 $request = new Request;

 $_SERVER['HTTP_HOST'] = 'example.com';
 $request->getHttpHost(); // example.com

 $_SERVER['HTTP_HOST'] = 'example.com:8080';
 $request->getHttpHost(); // example.com:8080

 $request->setStrictHostCheck(true);
 $_SERVER['HTTP_HOST'] = 'ex=am~ple.com';
 $request->getHttpHost(); // UnexpectedValueException

 $_SERVER['HTTP_HOST'] = 'ExAmPlE.com';
 $request->getHttpHost(); // example.com
doc_Phalcon
2016-10-16 09:51:08
Comments
Leave a Comment

Please login to continue.