What potential issues can arise when using the header() function in PHP, especially in terms of producing unnecessary traffic?
Using the header() function in PHP can potentially lead to unnecessary traffic if headers are sent multiple times or after content has already been outputted. To avoid this issue, make sure to call the header() function before any output is sent to the browser.
<?php
ob_start(); // Start output buffering
// Set header before any output
header('Location: http://example.com');
exit();
ob_end_flush(); // Flush output buffer
?>