• PHP Video Tutorials

PHP - Function Header Sent



Syntax

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

Definition and Usage

It will check whether header have been sent or not.

Return Values

If headers have already been sent than it will returns true or else false

Parameters

Sr.No Parameters & Description
1

file

It contains the information about file or line parameters

2

Line

It contains the line number where output has started.

Example

Try out following example

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

The above example will check whether headers have been sent or not, If it has sent, it shows a message or else it will send headers

php_function_reference.htm
Advertisements