What are some potential pitfalls to be aware of when using header("Location: ...") in PHP scripts?

Using header("Location: ...") in PHP scripts can lead to potential pitfalls such as header already sent errors if there is any output before the header function is called. To avoid this issue, make sure to call the header function before any output is sent to the browser.

<?php
// Correct way to use header("Location: ...") in PHP
ob_start(); // Start output buffering
header("Location: http://www.example.com");
exit();
ob_end_flush(); // Flush the output buffer
?>