I'm using PHP 7.2.0
I've installed the latest version of XAMPP on my machine that is running on Windows 10 Home Single Language 64-bit Operating System
I'm mainly using following web browsers :
- Google Chrome Version 63.0.3239.132 (Official Build) (64-bit)
- Firefox Quantum 57.0.4 (64-bit)
I'm trying to learn the header()
function in PHP
Consider below text and sample code from the PHP Manual:
string
The header string.
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.
<?php
header("HTTP/1.0 404 Not Found");
?>
First of all let me tell you frankly and honestly that I did not understand much of the part from the above text relating to the code below it. I want to understand the above text completely.
Following are the doubts I have and I want appropriate answers for each of my question in an easy to understand, simple and lucid language.
The HTTP status code is not figured out anywhere rather it is hard-coded into a string passed as an argument to the
header()
function.Then what does the sub-clause mean from the above text saying that
" 'HTTP/' (case is not significant), which will be used to figure out the HTTP status code to send"
?
I'm not understanding where the HTTP status code is figured out here as it's been simply hard-coded into the string passed as an argument to the header()
function.
How to configure Apache to use a PHP script to handle requests for missing files(using the ErrorDocument directive)?
In case if it is already configured how to check it?
How can I make sure that that my PHP script generates the proper HTTP status code?
Now, consider below text and sample code from the PHP 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.
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
Does the sub-clause
"it also returns a REDIRECT (302) status code to the browser"
- From the above text mean that the REDIRECT (302) status code is sent implicitly as the third argument of
header()
function? If yes, how should I check it? If no, what does this sub-clause actually mean? - What do the status codes 201 and 3xx mean and how do they affect the
header()
function?
Thank You.