PHP.mk документација

getallheaders

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.getallheaders.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.getallheaders.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
getallheaders

Референца за `function.getallheaders.php` со подобрена типографија и навигација.

function.getallheaders.php

getallheaders

(PHP 4, PHP 5, PHP 7, PHP 8)

getallheadersПреземи ги сите HTTP заглавија на барањето

= NULL

getallheaders(): array

Презема ги сите HTTP заглавија од тековното барање.

Оваа функција е алијас за apache_request_headers(). Ве молиме прочитајте го apache_request_headers() документацијата за повеќе информации за тоа како работи оваа функција.

Параметри

Оваа функција нема параметри.

Вратени вредности

Асоцијативен низ од сите HTTP заглавија во тековното барање.

Дневник на промени

Верзија = NULL
7.3.0 Оваа функција стана достапна во FPM SAPI.

Примери

Пример #1 getallheaders() example

<?php

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

?>

Види Исто така

Белешки од корисници Управување со PDO конекции

joyview на gmail точка com
пред 17 години
it could be useful if you using nginx instead of apache

<?php
if (!function_exists('getallheaders')) 
{
    function getallheaders() 
    {
           $headers = [];
       foreach ($_SERVER as $name => $value) 
       {
           if (substr($name, 0, 5) == 'HTTP_') 
           {
               $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
           }
       }
       return $headers;
    }
}
?>
Анонимен
пред 10 години
There's a polyfill for this that can be downloaded or installed via composer:

https://github.com/ralouphie/getallheaders
lorro на lorro точка hu
20 години пред
Beware that RFC2616 (HTTP/1.1) defines header fields as case-insensitive entities. Therefore, array keys of getallheaders() should be converted first to lower- or uppercase and processed such.
michaelmcandrew на thirdsectordesign точка org
пред 6 години
A simple approach to dealing with case insenstive headers (as per RFC2616) is via the built in array_change_key_case() function: 

$headers = array_change_key_case(getallheaders(), CASE_LOWER);
acidfilez на gmail точка com
пред 14 години
dont forget to add the content_type and content_lenght if your are uploading file:

<?php
  function emu_getallheaders() {
        foreach ($_SERVER as $name => $value) 
       {
           if (substr($name, 0, 5) == 'HTTP_') 
           {
               $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
               $headers[$name] = $value;
           } else if ($name == "CONTENT_TYPE") {
               $headers["Content-Type"] = $value;
           } else if ($name == "CONTENT_LENGTH") {
               $headers["Content-Length"] = $value;
           } 
       }
       return $headers;
    }
?>

chears magno c. heck
[email protected]
3 години пред
warning, at least on php-fpm 8.2.1 and nginx,  getallheaders() will return "Content-Length" and "Content-Type" both containing emptystring, even for requests without any of these 2 headers. you can do something like

<?php
$request_headers = getallheaders();
if(($request_headers["Content-Type"] ?? null) === "" && ($request_headers["Content-Length"] ?? null) === "") {
    // probably a getallheaders() bug, not actual request headers.
    unset($request_headers["Content-Type"], $request_headers["Content-Length"]);
}
?>

- might be a bug in nginx rather than php-fpm, i don't know. anyway a real request wouldn't leave them at emptystring
majksner на gmail точка com
пред 15 години
apache_request_headers replicement for nginx

<?php
if (!function_exists('apache_request_headers')) { 
        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; 
                }else{
                    $out[$key]=$value; 
        }
            } 
            return $out; 
        } 
}
?>
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.