Are there any best practices to follow when using header() for redirects in PHP?

When using the header() function for redirects in PHP, 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 additional code from executing. This helps avoid potential issues such as headers already being sent or unintended output being displayed before the redirect.

<?php
// Redirect to a new page
header("Location: https://www.example.com");
exit(); // Always include an exit() statement after header() to prevent further code execution
?>