The header() function is an predefined PHP native function.With header() HTTP functions we can control data sent to the client or browser by the Web server before some other output has been sent.
The header function sets the headers for an HTTP Response given by the server. We can do all sorts of things using the header function in PHP like Change page location, set timezone, set caching control, etc...
Some of the important uses of the header() in PHP are listed below:
It is used to redirect a from one web page to another web page in PHP.
header('Location:give your url here');
PHP defaults to sending Content-Type:text/html.If we want to change the Content-Type, we can achieve that with the header() function.
Generated PDF file :header('Content-Type: application/pdf'); Return response in json format:header('Content-Type: application/pdf');.
header("HTTP/1.0 404 Not Found");
The below example helps to prevent caching by sending header information which overrides browser setting to not-cache.
header("Cache-Control: no-cache, must-revalidate");