Differences between HTTP_HOST and SERVER_NAME in PHP

Source: Internet
Author: User
The differences between HTTP_HOST and SERVER_NAME in PHP are similar:
When the following three conditions are met, the two will output the same information.
1. the server is port 80.
2. set ServerName correctly in apache conf.
3. HTTP/1.1 Protocol specification

Differences:
1. general situation:
_ SERVER ["HTTP_HOST"] under the HTTP/1.1 protocol specification, information is output according to the client's HTTP request.
_ SERVER ["SERVER_NAME"] by default, the ServerName value in the configuration file httpd. conf of apache is directly output.

2. when the server is not port 80:
_ SERVER ["HTTP_HOST"] outputs the port number, for example, mimiz.cn: 8080.
_ SERVER ["SERVER_NAME"] directly outputs the ServerName value
Therefore, it can be understood as: HTTP_HOST = SERVER_NAME: SERVER_PORT

3. when the ServerName in the configuration file httpd. conf is inconsistent with the domain name of the HTTP/1.0 request:
Httpd. conf is configured as follows:

ServerName mimiz.cn
ServerAlias www.mimiz.cn

Client Access domain name www.mimiz.cn
_ SERVER ["HTTP_HOST"] outputs www.mimiz.cn
_ SERVER ["SERVER_NAME"] outputs mimiz.cn

Therefore, in actual programs, _ SERVER ["HTTP_HOST"] should be used as much as possible, which is relatively safe and reliable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.