We now have a youtube channel. Subscribe!

PHP | header_sent() Function

PHP header_sent() Function

Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP header_sent() Function.

The PHP header_sent() function checks if or where headers have been sent.


Following below is the syntax to use this function -

bool headers_sent ([ string &$file [, int &$line ]] )

Parameter Details

Sr.NoParameters & Description


It contains the information about file or line parameters



It contains the line number where output has started.

Return Value

This built-in PHP function TRUE if headers have already been sent, otherwise FALSE.


Try out the following example below -

   if (!headers_sent()) {
      header('Location: http://www.webdesigntutorialz.com/');
   if (!headers_sent($filename, $linenum)) {
      header('Location: http://www.webdesigntutorialz.com/');
   } else {
      echo "Headers already sent in $filename on line $linenum\n" .
         "Cannot redirect, for now please click this <a " .
         "href = \"http://www.webdesigntutorialz.com\">link</a> instead\n";


The following example above will check whether headers have been sent or not, if it has sent, it shows a message otherwise it will send headers.

Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the http_response_code() Function in PHP.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain