What are common pitfalls when using the header(Location) function in PHP for redirection?

Common pitfalls when using the header(Location) function in PHP for redirection include not using exit() after the header function, which can cause unexpected behavior due to the script continuing to execute. To solve this, always include exit() after setting the header location to ensure that the redirection occurs immediately.

<?php
header("Location: https://www.example.com");
exit();
?>