头信息很重要,2个人,一个叫服务器(服务端),一个叫浏览器(客户端),即有2个头信息,请求头信息和返回头信息。
那么如果通过php获取这些头信息,服务端想获取浏览器请求时的头信息,可以用$_server,代码如下:
$value){ $headers[$name] = $value; } return $headers; }var_dump(getheaderinfo());?>
输出:
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
可以看到不仅输出客户端的一些信息,也输出了服务端的一些信息。针对这些信息具体作用,这里不多介绍了,请查看http://www.cnblogs.com/iambetter/archive/2013/04/11/3014796.html
其实针对apache服务器可以使用现成的函数:getallheaders(),用这个函数的好处不多说了,直接看返回值吧
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)
完全没有类似于http_这样的参数,还需要去处理等问题。
知道如何获取请求过来的头信息了,那么也应该知道如何设置头信息,比如:
客户端获取到了服务端设置的头信息[name]
那么这个有什么用呢?其实有判断对方到底是什么请求?是同步请求呢,还是异步请求
2.html页面是请求页面
返回页面
结果:
完毕,说的不好大家见谅。