Who is the best? PHP header information

Source: Internet
Author: User

Header information 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,CodeAs follows:

 
<? Phpfunction getheaderinfo () {foreach ($ _ server as $ name => $ 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 _ cookies' => string 'bdshare _ firstime = 100' (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-7.19.5; E: \ mysql5.5 \ mysql \ bin; C: \ Program Files \ 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 _ soft' => 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 '20140901' (length = 4) 'Gateway _ interface' => string 'cgi/123' (length = 7) 'server _ Protocol' => string 'HTTP/123' (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, the following functions can be used for Apache servers:Getallheaders(). The benefits of using this function are not mentioned much. Let's look at the return value 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) 'access' => string 'text/html, application/XHTML + XML, application/XML; q = 0.9, */*; q = 0.8 '(length = 63) 'Accept-color' => 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) 'cookies' => 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:

 
<? Phpheader ("Name: anleb");?>

 

 

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

 
<HTML>  

Back to page

<? Phpif (isset (getallheaders () ['is _ Ajax ']) & getallheaders () ['is _ Ajax'] = 'yes') {echo 'yes ';} else {echo 'no';}?>

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.