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
- Are there any best practices to follow when writing SQL queries for sorting data in PHP applications?
- What methods can be used in PHP to reformat timestamps retrieved from a database to remove unnecessary characters?
- What are some best practices for describing coding issues in words for better understanding?