Home  >  Article  >  Backend Development  >  140 php $_SERVER variable

140 php $_SERVER variable

WBOY
WBOYOriginal
2016-07-29 09:03:051229browse

php $_SERVER variable


server variable

<code>/* 

That will give you the result <span>of</span> each variable like (<span>if</span> the file <span>is</span> server_indices.php at the root <span>and</span> Apache Web directory <span>is</span><span>in</span><span>E</span>:\web) : 

PHP_SELF    /server_indices.php 
argv    - 
argc    - 
GATEWAY_INTERFACE    CGI/<span>1.1</span>SERVER_ADDR    <span>127.0</span><span>.0</span><span>.1</span>SERVER_NAME    localhost 
SERVER_SOFTWARE    Apache/<span>2.2</span><span>.22</span> (Win64) PHP/<span>5.3</span><span>.13</span>SERVER_PROTOCOL    HTTP/<span>1.1</span>REQUEST_METHOD    GET 
REQUEST_TIME    <span>1361542579</span>REQUEST_TIME_FLOAT    - 
QUERY_STRING    
DOCUMENT_ROOT    <span>E</span>:<span>/web/</span>HTTP_ACCEPT    text<span>/html,application/xhtml+xml,application/xml;q=0.9,*/</span>*;q=<span>0.8</span>HTTP_ACCEPT_CHARSET    ISO-<span>8859</span>-<span>1</span>,utf-<span>8</span>;q=<span>0.7</span>,*;q=<span>0.3</span>HTTP_ACCEPT_ENCODING    gzip,deflate,sdch 
HTTP_ACCEPT_LANGUAGE    fr-FR,fr;q=<span>0.8</span>,en-US;q=<span>0.6</span>,en;q=<span>0.4</span>HTTP_CONNECTION    keep-alive 
HTTP_HOST    localhost 
HTTP_REFERER    <span>http</span>:<span>//</span>localhost/ 
HTTP_USER_AGENT    Mozilla/<span>5.0</span> (Windows NT <span>6.1</span>; WOW64) AppleWebKit/<span>537.17</span> (KHTML, like Gecko) Chrome/<span>24.0</span><span>.1312</span><span>.57</span> Safari/<span>537.17</span>HTTPS    - 
REMOTE_ADDR    <span>127.0</span><span>.0</span><span>.1</span>REMOTE_HOST    - 
REMOTE_PORT    <span>65037</span>REMOTE_USER    - 
REDIRECT_REMOTE_USER    - 
SCRIPT_FILENAME    <span>E</span>:/web/server_indices.php 
SERVER_ADMIN    myemail<span>@personal</span>.us 
SERVER_PORT    <span>80</span>SERVER_SIGNATURE    
PATH_TRANSLATED    - 
SCRIPT_NAME    /server_indices.php 
REQUEST_URI    /server_indices.php 
PHP_AUTH_DIGEST    - 
PHP_AUTH_USER    - 
PHP_AUTH_PW    - 
AUTH_TYPE    - 
PATH_INFO    - 
ORIG_PATH_INFO    - 

*/ </code>

The difference between HTTP_HOST and SERVER_NAME

Recently, when developing website group software, I have used issues related to determining subsites based on accessed domain names. PHP has two variables to get the current domain name, HTTP_HOST and SERVER_NAME. I would like to know the difference between the two and which one is more reliable.
First of all, I want to say that those articles floating around on Baidu are all nonsense!
Some say they are the same and some say they are different, without explaining the reasons. They just pass them around without verification, which is a waste of the audience's time.
Here is my summary after personal verification + consulting official documents + official BUG list + official mailing list + sitepoint + webmasterworld + google:
Similarities:
When the following three conditions are met, both will output the same information.
1. The server is port 80
2. The ServerName in apache’s conf is set correctly
3. HTTP/1.1 protocol specification
Differences:
1. Usually:
_SERVER["HTTP_HOST"] Under the HTTP/1.1 protocol specification, information will be output according to the client's HTTP request.
_SERVER["SERVER_NAME"] by default directly outputs the ServerName value in apache's configuration file httpd.conf.
2. When the server is not port 80:
_SERVER["HTTP_HOST"] will output the port number, for example: mimiz.cn:8080
_SERVER[“SERVER_NAME”] will directly output the ServerName value
So in this case, 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 requested by HTTP/1.0:
httpd.conf is configured as follows:

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced the 140 php $_SERVER variables, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn