"Headers already sent" error in PHP

  • Jan 09, 2023
  • 1
  • 667

How to fix the below error when running the script?

Warning: Cannot modify header information - headers already sent by (output started at /folder/index.php:18) in /folder/index.php on line 35

The above line mentioned in the error messages contains header() and setcookie() calls.

Answers (1)
Answer Accepted

As per the PHP documentation:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

So move header('Location: reset.php?username='.$username); before any other kind of output.

Please refer to the below links for more details,

Submit your answer