Who is the best? Php header information

Source: Internet
Author: User
Who is the best? The header information about Php is very important. two people, one is a server and the other is a browser (client). There are two headers, request header information and response header information.

If you use php to obtain the header information, the SERVER can use $ _ SERVER to obtain the header information of the browser request. the code is as follows:

  $value){ $headers[$name] = $value;      }      return $headers;  }var_dump(GetHeaderInfo());?>

Output:

array (size=32)  'HTTP_HOST' => string 'localhost' (length=9)  'HTTP_USER_AGENT' => string 'Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0' (length=65)  'HTTP_ACCEPT' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' (length=63)  'HTTP_ACCEPT_LANGUAGE' => string 'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3' (length=35)  'HTTP_ACCEPT_ENCODING' => string 'gzip, deflate' (length=13)  'HTTP_COOKIE' => string 'bdshare_firstime=1365907820098' (length=30)  'HTTP_CONNECTION' => string 'keep-alive' (length=10)  'HTTP_CACHE_CONTROL' => string 'max-age=0' (length=9)  'PATH' => string 'C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;D:\svn\bin;D:\curl\curl-7.19.5;E:\mysql5.5\mysql\bin;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Ruby193\bin;C:\Program Files\SinoVoice\jTTS 5.0 Desktop\Bin;D:\php\xampp\php;C:\wamp\bin\php\php5.4.3\php.exe;' (length=266)  'SystemRoot' => string 'C:\WINDOWS' (length=10)  'COMSPEC' => string 'C:\WINDOWS\system32\cmd.exe' (length=27)  'PATHEXT' => string '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH' (length=48)  'WINDIR' => string 'C:\WINDOWS' (length=10)  'SERVER_SIGNATURE' => string '' (length=0)  'SERVER_SOFTWARE' => string 'Apache/2.2.22 (Win32) PHP/5.4.3' (length=31)  'SERVER_NAME' => string 'localhost' (length=9)  'SERVER_ADDR' => string '127.0.0.1' (length=9)  'SERVER_PORT' => string '80' (length=2)  'REMOTE_ADDR' => string '127.0.0.1' (length=9)  'DOCUMENT_ROOT' => string 'C:/wamp/www/' (length=12)  'SERVER_ADMIN' => string 'admin@localhost' (length=15)  'SCRIPT_FILENAME' => string 'C:/wamp/www/1.php' (length=17)  'REMOTE_PORT' => string '2483' (length=4)  'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)  'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)  'REQUEST_METHOD' => string 'GET' (length=3)  'QUERY_STRING' => string '' (length=0)  'REQUEST_URI' => string '/1.php' (length=6)  'SCRIPT_NAME' => string '/1.php' (length=6)  'PHP_SELF' => string '/1.php' (length=6)  'REQUEST_TIME_FLOAT' => float 1366034246.187  'REQUEST_TIME' => int 1366034246

We can see that not only some information about the client is output, but also some information about the server. For the specific role of this information, here is not much introduction, please refer to the http://www.cnblogs.com/IAmBetter/archive/2013/04/11/3014796.html

In fact, a ready-made function can be used for apache servers: getallheaders (). the benefits of using this function are not mentioned. let's look at the returned values directly.

array (size=8)  'Host' => string 'localhost' (length=9)  'User-Agent' => string 'Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0' (length=65)  'Accept' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' (length=63)  'Accept-Language' => string 'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3' (length=35)  'Accept-Encoding' => string 'gzip, deflate' (length=13)  'Cookie' => string 'bdshare_firstime=1365907820098' (length=30)  'Connection' => string 'keep-alive' (length=10)  'Cache-Control' => string 'max-age=0' (length=9)

There are no parameters similar to HTTP _, and you still need to handle them.

If you know how to obtain the request header information, you should also know how to set the header information, such:

 

The client obtains the header information set by the server. [name]

So what is the purpose of this? Actually, is there a way to determine what request the other party is? Is it a synchronous request or an asynchronous request?

2.html page: request page

 Script function CallAjax () {var xmlHttp = new XMLHttpRequest (); xmlHttp. open ("POST", '1. php', false); xmlHttp. setRequestHeader ("Is_Ajax", "yes"); xmlHttp. send ("name = anleb"); result = xmlHttp. responseText; alert ("Result:" + result);} script

Back to page

 

Result:

Sorry.

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.