14

I am trying to switch from apache to nginx on my server. The only problem here is the getallheaders() function I used in my PHP scripts which does not work with Nginx. I have tried the user contributed notes on php site on getallheaders finction but that does not return all request headers.

Please tell me how to solve this problem. I would really like to switch to Nginx.

adityap
  • 729
  • 4
  • 8
  • 19

2 Answers2

10

You can still use it but you will have to re-define/re-write it like here

http://www.php.net/manual/en/function.getallheaders.php#84262

0xAli
  • 1,059
  • 10
  • 22
  • I have used this method but no luck. It doesnt give me all the headers that I want. For example my app requires client to send "owner-id" header. This is can't get with any function except getallheaders(). – adityap May 16 '11 at 11:29
  • Is the header value sent for each page the same? or different for each page? – 0xAli May 16 '11 at 15:04
  • 2
    Like someone later posted on the page, make sure you take Content-Type and Content-Length into account, as they don't follow the same naming convention. See this post:http://www.php.net/manual/en/function.getallheaders.php#104307 – ryanbrainard Jun 28 '11 at 03:36
6

A request header of Owner-ID will be passed to php as $_SERVER['HTTP_OWNER_ID'] by nginx. All request headers are passed in a similar manner.

kolbyjack
  • 17,660
  • 5
  • 48
  • 35
  • 1
    I just tested by calling a php script containing using curl -H 'Owner-ID: foobar' and $_SERVER['HTTP_OWNER_ID'] has a value of foobar. Did you maybe disable this behavior with fastcgi_pass_request_headers off;? – kolbyjack May 18 '11 at 13:21
  • I have uninstalled nginx... It may be providing headers this way but has many other problems like you cant install module without recompiling the server. This is annoying to deploy on production servers. I would like to remain on apache now until nginx become mature enough. Anyway thanks for the help – adityap May 19 '11 at 05:13