The PHP Header function is used to send HTTP Headers in response to a HTTP request, typically coming from a browser. Headers must be sent before any output is sent to the browser.
To send a simple header response, such as that used for permanent redirects, we may use the below:
Header( “HTTP/1.1 301 Moved Permanently” ); Header( “Location: http://beamtic.com/new-url” );
Status codes are used to tell the browser if the requested resource exists, has been modified, or if it has been moved to another location.
The standard response for a PHP script is 200 OK, but we can change this using the PHP header function. We would typically do this for caching purposes, or to redirect the request in case the resource was moved. To send a 200 ok message we can do like this:
header('HTTP/1.1 200 OK');
header('HTTP/1.1 303 See Other'); header('Location: http://www.example.com/');
- HTTP Response Codes – a list of response codes.