0

When I redirect users using the header() function, only passing the first argument, what response code will be send?

I had header('Location: https://' . $_SERVER['HTTP_HOST']); set for some time on old pages, and now I'm curious if that redirect might have been cached by browsers.

3
  • 200 is the default OK response. Commented Sep 25, 2017 at 15:09
  • When you redirect them how? Using Location: ... ? Commented Sep 25, 2017 at 15:11
  • 1
    if you use header("Location" you should get a 302. You can read this in the docs already. Or you could have tested it about as quickly as writing a question Commented Sep 25, 2017 at 15:13

3 Answers 3

3

It will send a 302 (temporary redirect) if you send a Location header and don't specify otherwise. From the manual:

The second special case is the "Location:" header. Not only does it send this header back to the browser, but it also returns a REDIRECT (302) status code to the browser unless the 201 or a 3xx status code has already been set.

Edit: So, to answer your follow-up query: no, this should not have been cached.

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

Comments

0
  • 200 when the page loads
  • 404 when the page cannot be found
  • 500 when the page returnes an error
  • etc...

https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Comments

0

There are two special-case header calls. The first is a header that starts with the string "HTTP/" (case is not significant), which will be used to figure out the HTTP status code to send. For example, if you have configured Apache to use a PHP script to handle requests for missing files (using the ErrorDocument directive), you may want to make sure that your script generates the proper status code.

for more details , please check http://php.net/manual/en/function.header.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.