1

I see somewhere people doing something like:

<?php
header('HTTP/1.0 200 OK');
header('HTTP/1.1 200 OK');
?>

What's the purpose of this? Seems the second one will always overwrite the first header? Or is this because if some clients doesn't support http 1.1 so they can still receive a 1.0 header?

Zeyang
  • 69
  • 5

1 Answers1

3

There is no purpose to this. Only one HTTP status line can be sent to the client.

The default is to send 200 OK anyway, so unless you're overriding a previous status line (which would be strange), then both lines are pointless.

If you are using PHP 5.4+, you should use http_response_code() to set the status code anyway. Leave the protocol implementation up to the web server.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • What happens if a client request doesn't support 1.1 in this case? He gets a null header or receive that 1.0 header? – Zeyang Nov 03 '14 at 18:08
  • 1
    @Zeyang It isn't a header, it's the status line. It's a bit different than a header. There will always be a status line. What HTTP version used depends entirely on how the upstream server handles this sort of data. It will vary from system to system. You should test it in your specific configuration. In practice, it won't matter since HTTP/1.1 is mostly backwards compatible with 1.0. – Brad Nov 03 '14 at 18:11
  • Right, I meant status line. Thanks for the in detail explanation. – Zeyang Nov 03 '14 at 18:16