Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the HTTP_HOST server variable always defined?

Tags:

php

iis

apache

Is the server variable HTTP_HOST always defined for all servers, or for example in IIS is defined with other name or even is not defined at all?

Also, that value is always defined? Or some host they don't define that value? Is there any other way to retrieve that value?

like image 308
KodeFor.Me Avatar asked Jun 06 '12 08:06

KodeFor.Me


People also ask

What is the $_ server variable?

$_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.

What are server variables?

IIS Server Variables provide information about the server, the connection with the client, and the current request on the connection. Additionally, inbound URL rewrite rules can be used to set custom server variables.

What is HTTP_HOST in Apache?

The HTTP_HOST is obtained from the HTTP request header and this is what the client actually used as "target host" of the request. The SERVER_NAME is defined in server config.

What is $host variable in nginx?

$host is the value of Host in request header, without the port number. If that is not present in request header, then it assumes the value of server_name directive in NGINX configuration. If there are multiple values in server_name directive, then $host will use the first value and ignore the rest.


2 Answers

Quoting the manual

HTTP_HOST is

Contents of the Host: header from the current request, if there is one. 

HTTP_HOST is a part of the client's HTTP request and specifies which host name the request is to be directed to. if HTTP_HOST is not set, the client is either very, very old (HTTP 1.0 doesn't support HTTP_HOST) or has made a request directly to your web site's IP.

I think the Host HTTP Header is mandatory since HTTP 1.1

like image 138
verisimilitude Avatar answered Oct 12 '22 23:10

verisimilitude


HTTP_HOST is not defined by server, it's

Contents of the Host: header from the current request, if there is one.

So it depends on whether the header info of your request contain Host.

like image 23
xdazz Avatar answered Oct 12 '22 23:10

xdazz