What are best practices for handling URL redirects in PHP without using JavaScript?

When handling URL redirects in PHP without using JavaScript, it is recommended to use the header() function to send a raw HTTP header to perform the redirection. This function sends a raw HTTP header to the browser, indicating a redirection to a new URL. It is important to use this function before any output is sent to the browser to avoid any errors.

<?php
// Perform a URL redirect using the header() function
header("Location: https://www.example.com/newpage.php");
exit; // Make sure to exit after the redirect to prevent further execution
?>