欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP獲取http請求的頭信息實(shí)現(xiàn)步驟

 更新時(shí)間:2012年12月16日 14:36:01   作者:  
PHP如何獲取http請求頭信息,是一個(gè)急切解決而不知道如何抉擇的問題,本人搜集整理下,可供參考下
PHP手冊提供了現(xiàn)成的函數(shù):
getallheaders
(PHP 4, PHP 5)
getallheaders — Fetch all HTTP request headers
說明
array getallheaders ( void )
Fetches all HTTP headers from the current request.
This function is an alias for apache_request_headers(). Please read theapache_request_headers() documentation for more information on how this function works.
返回值
An associative array of all the HTTP headers in the current request, orFALSE on failure.
Example #1 getallheaders() example
復(fù)制代碼 代碼如下:

<?php
foreach (getallheaders() as $name => $value) {
echo "$name: $value\n";
}
?>

不過這個(gè)函數(shù)只能在apache環(huán)境下使用,iis或者nginx并不支持,可以通過自定義函數(shù)實(shí)現(xiàn)
復(fù)制代碼 代碼如下:

<?php
<SPAN class=html>if (!function_exists('getallheaders'))
{
&nbsp;&nbsp;&nbsp; function getallheaders()
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp; &nbsp; &nbsp; foreach ($_SERVER as $name => $value)
&nbsp;&nbsp; &nbsp; &nbsp; {
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (substr($name, 0, 5) == 'HTTP_')
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp;&nbsp; &nbsp; &nbsp; }
&nbsp;&nbsp; &nbsp; &nbsp; return $headers;
&nbsp;&nbsp;&nbsp; }
}</SPAN>
?>

好了,看看都打印出了啥吧
復(fù)制代碼 代碼如下:

<?php
print_r(getallheaders());

獲得結(jié)果:
復(fù)制代碼 代碼如下:

Array
(
[Accept] => */*
[Accept-Language] => zh-cn
[Accept-Encoding] => gzip, deflate
[User-Agent] => Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)
[Host] => localhost
[Connection] => Keep-Alive
)

相關(guān)文章

最新評論