What best practices should be followed when using headers for redirection in PHP scripts?
When using headers for redirection in PHP scripts, it is important to follow best practices to ensure proper functionality and security. One key best practice is to always include an exit or die statement after the header function to prevent any further code execution. Additionally, it is recommended to use absolute URLs for redirection to avoid potential security risks such as open redirect vulnerabilities.
<?php
// Redirect to a specific page using absolute URL
header("Location: https://example.com/newpage.php");
exit;
?>