Home >Backend Development >PHP Tutorial >What is header() function in PHP?
The header() function is a predefined PHP native function. The header() HTTP function allows us to control the data that the web server sends to the client or browser before sending other output.
The header function sets the headers of the HTTP response given by the server. We can use the header function in PHP to do various things, such as changing the page location, setting the time zone, setting cache control, etc...
Listed some important uses of header() in PHP as follows :
Used to redirect one web page to another web page in PHP.
header('Location:give your url here');
PHP sends Content-Type: text/html by default. If we want to change the Content-Type, we can use the header() function to do so.
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 following example helps prevent caching by sending header information that overrides the browser's settings to not cache.
header("Cache-Control: no-cache, must-revalidate");
The above is the detailed content of What is header() function in PHP?. For more information, please follow other related articles on the PHP Chinese website!