Fakeer
Fakeer

Reputation: 1034

Get headers on Appengine GAE PHP

I found out that the common PHP function getallheaders() is unavailable on GAE. How do i access custom headers set by the client? For example an AJAX post contains a header "RestAuth: pk_1234123".

Upvotes: 1

Views: 644

Answers (2)

Fakeer
Fakeer

Reputation: 1034

To follow up @Stuart..straight from the man page referenced by @Tom

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; 
    } 
} 

So basically from your client you post RestAuth which turns into HTTP_RESTAUTH on the server which above function will finally return as Restauth. Play with the ucwords() if you prefer differently.

Upvotes: 1

Stuart Langley
Stuart Langley

Reputation: 7054

getallheaders() is an apache extension.

You can retrieve the headers from the $_SERVER superglobal. All of the request headers are capitalized and the header name is prepended with 'HTTP_'.

In you're case, the header 'RestAuth' would be available as $_SERVER['HTTP_RESTAUTH'].

Upvotes: 2

Related Questions