How can the presence of UTF-8 with BOM encoding in a PHP script file potentially cause issues with the headers_sent() function and header modification?

When a PHP script file is encoded in UTF-8 with BOM (Byte Order Mark), it can cause issues with the `headers_sent()` function and header modification because the BOM characters are treated as output before any headers are sent. To solve this issue, you can remove the BOM characters from the PHP script file or use output buffering to prevent the BOM characters from being sent before headers.

// Start output buffering to prevent BOM characters from being sent before headers
ob_start();

// Your PHP code here

// Check if headers have been sent
if (headers_sent()) {
    // Headers have been sent, handle the situation accordingly
} else {
    // Modify headers here
}

// Flush the output buffer
ob_end_flush();