0

I am very new to PHP as this is the first time I am using it to develop a tool. Basically, I have been surfing the web for functions that are capable of extracting HTTP request header information and so far all I have been able to find are functions that return the word array. I know this is definitely me misunderstanding how to use the function and or arrays but a little clarity would be nice.


 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; 
    } 
 echo emu_getallheaders();

1 Answers1

-1

It looks like that function probably does what you want it to. The problem is that it returns an array, and you can't echo an array. If you want to see what the function returns, you can use var_dump instead.

$headers = emu_getallheaders();
var_dump($headers);
Don't Panic
  • 41,125
  • 10
  • 61
  • 80
  • This is a duplicate question, as I am sure you are aware. Please close duplicates rather than answering so that they can be easily removed by Roomba. – mickmackusa Apr 19 '19 at 21:10