Are there any best practices for handling automatic redirection in PHP scripts?

When handling automatic redirection in PHP scripts, it is important to ensure that the redirection is done securely and efficiently. One best practice is to use the header() function to send the appropriate HTTP headers for redirection. Additionally, it is recommended to use exit() or die() after the header() function to stop the script execution and prevent any further code from being executed.

<?php

// Perform any necessary checks before redirection
if ($condition) {
    // Redirect to the desired URL
    header('Location: http://www.example.com/new_page.php');
    exit(); // Stop script execution
}

?>