Google+Find us on Google+
How to resolve “header already sent error in PHP” while redirecting

How to resolve “header already sent error in PHP” while redirecting

The header already sent error in PHP is a very common error.The main reason behind header already sent is, before the redirect code starts you already have some output.

What is header, as per

header() is used to send a raw HTTP header. See the » HTTP/1.1 specification for more information on HTTPheaders.

In simple terms, header is a function where you can pass some methods  for the action you need done.Defining a page 404 in PHP using header for

Making status code  404 in PHP using Header

or redirect using header in PHP

Here is solution on how you can prevent header already sent error in PHP

  • Make sure no output is sent (print) before the PHP redirect using the header function, be it HTML code or white space or just a new line.
  • If you aren’t sure of output then do the following, right click -> click the view source. If there is any output then you will be able to recognize it.
  • Use below method to redirect, which checks if header is already sent, if yes then use alternate methods to redirect

If you have any issue regards header error in PHP then don’t hesitate to comment, I will help you out.

Please take a moment and contribute to web community by sharing this article.

About Author


I am a Passionate Web Developer, Adventure Seeker, Hobbyist Blogger, Amazed by Tech, Party Lover, big Foodie and list goes on.