7

Until now my php application assumed HTTP 1.1 everywhere. So I defined all headers like so:

header("HTTP/1.1 500 Internal Server Error"); 

But now my server also supports HTTP 2 and I want to update all header responses with the right HTTP status code.

How to I get the HTTP Protocol version of the http request?

(My webserver is nginx, but I guess it is irrelevant if I am using nginx or apache.)

Pascal Klein
  • 23,665
  • 24
  • 82
  • 119

2 Answers2

15

The server protocol should be available through SERVER_PROTOCOL from the server environment, usually exposed through $_SERVER['SERVER_PROTOCOL'] inside your application.

From phpinfo() under Apache 2.4:

SERVER_PROTOCOL => HTTP/1.1
MatsLindh
  • 49,529
  • 4
  • 53
  • 84
1

changing /etc/nginx/factcgi_params:

#fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  SERVER_PROTOCOL    HTTP/2.0;

Header should be:-

header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
Taufik Nurrohman
  • 3,329
  • 24
  • 39
Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42