3/15/2023 0 Comments Php strpos![]() Update: after checking the answer of Pekka on your question which contains a link to bobince's answer that PHP would always return HTTP_HOST's value for SERVER_NAME, which goes against my own PHP 4.x + Apache HTTPD 1.2.x experiences from a couple of years ago, I blew some dust from my current XAMPP environment on Windows XP (Apache HTTPD 2.2.1 with PHP 5.2.8), started it, created a PHP page which prints the both values, created a Java test application using URLConnection to modify the Host header and tests taught me that this is indeed (incorrectly) the case.Īfter first suspecting PHP and digging in some PHP bug reports regarding the subject, I learned that the root of the problem is in web server used, that it incorrectly returned HTTP Host header when SERVER_NAME was requested. For optimal reliability and predictability, you should specify an explicit hostname and port using the ServerName directive. If no port is specified in the ServerName, then the server will use the port from the incoming request. If no ServerName is specified, then the server attempts to deduce the hostname by performing a reverse lookup on the IP address. Taking Apache HTTPD as an example, here's an extract from its documentation: You however need to ensure that the webserver in question has the SERVER_NAME correctly configured. ![]() ![]() You should now however realize that the one is a client-controlled value which may thus not be reliable for use in business logic and the other is a server-controlled value which is more reliable. Which one to use depends on what you need it for. The SERVER_NAME is defined in server config. The HTTP_HOST is obtained from the HTTP request header and this is what the client actually used as "target host" of the request. What is the difference between HTTP_HOST and SERVER_NAME in PHP?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |