When running my script, I am getting several errors like this :
Warning: Cannot modify header information - headers already sent by (output started at /some/file.php:12) in /some/file.php on line 23
The lines mentioned in the error messages contain header() and setcookie() calls.
What could be the reason for this? And how to fix it ?
Solution : No output before sending headers !
Some functions modifying the HTTP header are:
- header / header_remove
- session_start / session_regenerate_id
- setcookie / setrawcookie
Output can be:
- Whitespace before <?php or after ?>
- The UTF-8 Byte Order Mark specifically
- Previous error messages or notices
- print, echo and other functions producing output
- Raw <html> sections prior <?php code.