downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

apache_reset_timeout> <apache_note
[edit] Last updated: Fri, 24 May 2013

view this page in

apache_request_headers

(PHP 4 >= 4.3.0, PHP 5)

apache_request_headersTüm HTTP istek başlıklarını alır

Açıklama

array apache_request_headers ( void )

Geçerli isteğin tüm HTTP istek başlıklarını alır.

Bu işlev sadece PHP bir Apache modülü olarak kuruluysa desteklenir.

Dönen Değerler

Başarı halinde mevcut isteğin tüm HTTP başlıklarını içeren bir ilişkili dizi döndürür; aksi halde FALSE döndürür.

Sürüm Bilgisi

Sürüm: Açıklama
4.3.3

PHP 4.3.3'ten itibaren bu işlevi, NSAPI sunucu modülü ile Netscape/iPlanet/SunONE sunucularında da kullanabilirsiniz.

4.3.0 PHP 4.3.0'dan önceki sürümlerde apache_request_headers() işlevinin ismi getallheaders() idi. PHP 4.3.0'dan itibaren getallheaders() işlevi apache_request_headers() işlevinin takma adıdır.

Örnekler

Örnek 1 - apache_request_headers() örneği

<?php
$headers 
apache_request_headers();

foreach (
$headers as $header => $value) {
    echo 
"$header$value <br />\n";
}
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0
Host: www.example.com
Connection: Keep-Alive

Notlar

Bilginize:

PHP'yi bir Apache modülü olarak kullansanız da kullanmasanızda genel CGI değişkenlerini çevre değişkenlerini okuyarak da alabilirsiniz. Kullanılabilir ortam değişkenlerinin listesini almak için phpinfo() işlevini kullanabilirsiniz.

Ayrıca Bakınız



apache_reset_timeout> <apache_note
[edit] Last updated: Fri, 24 May 2013
 
add a note add a note User Contributed Notes apache_request_headers - [3 notes]
up
1
callum85 at notspam dot msn dot com
6 years ago
There is a simple way to get request headers from Apache even on PHP running as a CGI. As far as I know, it's the only way to get the headers "If-Modified-Since" and "If-None-Match" when apache_request_headers() isn't available. You need mod_rewrite, which most web hosts seem to have enabled. Put this in an .htacess file in your web root:

RewriteEngine on
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]

The headers are then available in PHP as
<?php
  $_SERVER
['HTTP_IF_MODIFIED_SINCE'];
 
$_SERVER['HTTP_IF_NONE_MATCH'];
?>

I've tested this on PHP/5.1.6, on both Apache/2.2.3/Win32 and Apache/2.0.54/Unix, and it works perfectly.

Note: if you use RewriteRules already for clean URLs, you need to put the above rules AFTER your existing ones.
up
1
limalopex.eisfux.de
6 years ago
I didn't found a replacement for apache_request_headers() in PHP::Compat (http://pear.php.net/package/PHP_Compat) so I wrote my own:

<?php
if( !function_exists('apache_request_headers') ) {
///
function apache_request_headers() {
 
$arh = array();
 
$rx_http = '/\AHTTP_/';
  foreach(
$_SERVER as $key => $val) {
    if(
preg_match($rx_http, $key) ) {
     
$arh_key = preg_replace($rx_http, '', $key);
     
$rx_matches = array();
     
// do some nasty string manipulations to restore the original letter case
      // this should work in most cases
     
$rx_matches = explode('_', $arh_key);
      if(
count($rx_matches) > 0 and strlen($arh_key) > 2 ) {
        foreach(
$rx_matches as $ak_key => $ak_val) $rx_matches[$ak_key] = ucfirst($ak_val);
       
$arh_key = implode('-', $rx_matches);
      }
     
$arh[$arh_key] = $val;
    }
  }
  return(
$arh );
}
///
}
///
?>
up
-3
jrabbit
6 years ago
The following code will implement an approximation of apache_request_headers for lighttpd making most scripts that use the function portable between the two platforms.

Caveats are:

1. This function will convert any _ in a header key to a -

2. This function will capitalize the first character and first character after each hyphen in each header key and lower case the rest of the key.

This does not cause a problem with standard headers which are capitalized in this manner but may cause custom headers to appear in a different case to apache.

<?php
if (!function_exists('apache_request_headers')) {
    eval(
'
        function apache_request_headers() {
            foreach($_SERVER as $key=>$value) {
                if (substr($key,0,5)=="HTTP_") {
                    $key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
                    $out[$key]=$value;
                }
            }
            return $out;
        }
    '
);
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites