What best practice should be followed when using the header() function in PHP to avoid header modification errors?
When using the `header()` function in PHP, it is important to avoid sending any output before calling this function. This is because headers must be sent before any actual output is sent to the browser. To prevent header modification errors, make sure to call `header()` before any `echo` or `print` statements in your PHP code.
<?php
// Correct way to use header() function to avoid header modification errors
ob_start(); // Start output buffering
header('Location: https://www.example.com');
ob_end_flush(); // Flush the output buffer and send the headers
exit; // Stop script execution
?>