What is the purpose of the header() function in PHP?
The header() function in PHP is used to send raw HTTP headers to the client. It is commonly used to redirect users to a different page, set cookies, specify content type, prevent caching, and handle other HTTP header operations. This function is crucial for controlling the behavior of web pages and ensuring proper communication between the server and client.
<?php
// Redirecting to a different page
header("Location: https://www.example.com");
exit();
?>
Related Questions
- How can PHP developers ensure that the output of code stored in a database is accurately represented without unintended transformations?
- What are the potential pitfalls of using incorrect syntax, such as $SESSION_ instead of $_SESSION in PHP code?
- How can PHP configuration settings affect the execution of PHP scripts from HTML pages?