Jump to content

When is http_response_code() ever needed?


Go to solution Solved by Jacques1,

Recommended Posts

http://php.net/manual/en/function.http-response-code.php will Get or Set the HTTP response code.

 

Why would one ever need to do so?

 

The documentation appears to just return an integer.  Does it send headers as well?  Guess that would be nice so I don't need to create them myself such as "HTTP/1.1 200 OK".  I would like to leave the default at 200, but only do differently explicitly.  But doesn't it change it for future?

Edited by NotionCommotion
Link to comment
https://forums.phpfreaks.com/topic/301393-when-is-http_response_code-ever-needed/
Share on other sites

The function sets (or gets) the HTTP code of the upcoming response. It does not send any headers. The big advantage over setting the code manually with a header() call is that you can omit the HTTP version as well as the reason phrase (“OK”, “Not Found”, ...). PHP will figure those out for you.

 

I use the function regularly, e. g. for error handling (issue a 400 code if the input validation failed).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.