Send HTTP headers before or after a cookie header?

I was wondering if there was any problem or difference between sending regular headers before or after sending cookie headers. Do some browsers prefer a specific order to headers? If the cookie header is large, will subsequent headers never be parsed?

setcookie("TestCookie", $value);
header("Content-type: text/javascript");

or

header('Location: http://www.example.com/');
setcookie("TestCookie", $value);

or

setcookie("SuperLargeCookie", $massive_value);
setcookie("TinyCookie", $small_value);
header("Status: 404 Not Found");
+3
source share
3 answers

There is no difference. The Http protocol does not indicate that headers should be in a specific order. Browsers do not differ depending on the order of the headers.

Http . , . 8K 16K. .

+4

, HTTP- . setcookie() :

Set-Cookie: SuperLargeCookie=whatever; Max-Age=3600; Version=1

header():

Location: http://www.example.com/redirect
+2

HTTP- , , . , . , ( ) . HTTP, HTTP-:

Cookie: TestCookie=value\r\n
Content-type: text/javascript\r\n
\r\n

, , , , - 200 OK, ... header :

<?php
header("HTTP/1.0 404 Not Found");
?>

With the PHP header function, just make sure you don't write text before releasing it. Otherwise, you can ruin everything.

+1
source

Source: https://habr.com/ru/post/1777113/


All Articles