What are the best practices for handling HTTP header redirection in PHP scripts?
When handling HTTP header redirection in PHP scripts, it is important to ensure that the header function is used before any output is sent to the browser. This is because headers must be sent before any content to avoid errors. It is also good practice to include an exit statement after sending the header to prevent any further code execution.
<?php
// Redirect to a new page
header("Location: https://www.example.com");
exit;
?>