Jump to content

When do SERVER_NAME and HTTP_HOST differ?


estelle

Recommended Posts

Hi,

Can anyone provide examples of where $_SERVER['SERVER_NAME'] and $_SERVER['HTTP_HOST'] would differ?

The only example I've found is when running on localhost becaues I use a specific port and the two variables come out as:
$_SERVER['HTTP_HOST'] --> localhost:10001
$_SERVER['SERVER_NAME'] --> localhost

Are there occasions where one variable will be blank and the other will be set?

TIA :)
Link to comment
Share on other sites

'SERVER_NAME'

    The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.

'HTTP_HOST'

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


Going by that description, SERVER_NAME should be more stable, since it's defined by the web server.  HTTP_HOST will probably have more variance.

I haven't answered your question, but I hope this helps :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.