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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.