• 3
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Are they all stored in $_SERVER? Even custom ones?

Every HTTP request header field is in $_SERVER (except Cookie) and the key begins with HTTP_. If you’re using Apache, you can also try apache_request_headers.

  • 21
Reply Report

You can simply use apache_request_headers() or its alias getallheaders().

Usage: echo json_encode(getallheaders());

If above function does not exist (old PHP or nginx) you can use this as a fallback:

<?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; 
    } 
}
?>
  • 8
Reply Report

Look at the $_SERVER variable to see what it contains. The linked manual page has a lot of useful information, but also simply do a var_dump on it to see what's actually in it. Many of the entries will or won't be filled in, depending on what the client decides to do, and odd quirks of PHP. Looking at the one on my local server, there is also a $_SERVER["ALL_HTTP"] entries that just lists them all as a string, but apparently this isn't standard, as it isn't listed on the manual page.

  • 6
Reply Report

you can use apache_request_header(); maybe help you.

$headers = apache_request_headers();        
foreach ($headers as $header => $value) {
 echo "<pre>";
 echo "$header : $value";
 echo "</pre>";
}
  • 0
Reply Report

What's happening is that http headers' names are rewritten:

  1. Prefixed with HTTP_
  2. Replaced '-' by '_'
  3. Upper Cased

That's at least what I've observed for my custom headers and apache 2.4. This is not canonical nor a comprehensive list of what you should check, but it may lead you to the right direction as for me none of the above helped.

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions