0

If I have two headers like:

header("Cache-Control: public"); header("Cache-Control: private"); 

Which will be effective (first or last)?

5
  • 1
    Quite easy to test, isn't it? Commented Oct 27, 2015 at 17:38
  • 1
    Do you understand what private and public actually mean wrt Cache-Control headers? Commented Oct 27, 2015 at 17:39
  • it's the daily quiz. Commented Oct 27, 2015 at 17:47
  • 1
    Headers will be overriden if defined more than once. So, the second one. Commented Oct 27, 2015 at 17:49
  • About the specify case of cache-control, see this answer Commented Oct 27, 2015 at 17:52

1 Answer 1

1

On this script the second header() will be used:

<?php header('Location: http://google.de'); header('Location: http://stackoverflow.com'); 

On your script the second header() will be used:

<?php header("Cache-Control: public"); header("Cache-Control: private"); 

If a header was defined multiple times, the last one will be used!

Sign up to request clarification or add additional context in comments.

3 Comments

To elaborate on this answer, if an exit; were placed after the first header, then the last one will not execute.
Yes with die() too.
Ok,that's right! Thank you for answer my dumb question. You are awesome!