What are some potential pitfalls when using the header() function in PHP?
One potential pitfall when using the header() function in PHP is that it must be called before any output is sent to the browser. If there is any output, such as HTML content or whitespace, before calling header(), it will result in a "headers already sent" error. To avoid this issue, make sure to call header() before any output is generated.
<?php
// Correct way to use header() function
header("Location: https://www.example.com");
exit;
?>