What best practices should be followed when implementing a redirect in PHP code?

When implementing a redirect in PHP code, it is important to follow best practices to ensure proper functionality and security. One common method is to use the header() function to send a Location header with the desired URL. It is also recommended to use exit() or die() after the header function to prevent any further code execution.

<?php
// Redirect to a new page
header("Location: https://www.example.com");
exit();
?>