Why am i seeing a 'headers already sent' error in php?

This error usually occurs when you try to modify headers after sending output to the browser.

Example:


  echo 'Hello';
  header('Location: anotherpage.php');
  

Solution:


  ob_start();
  echo 'Hello';
  header('Location: anotherpage.php');
  ob_end_flush();
  

Beginner's Guide to PHP