<HTML ><HEAD ><TITLE >headers_sent</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="HTTP functions" HREF="ref.http.html"><LINK REL="PREVIOUS" TITLE="header" HREF="function.header.html"><LINK REL="NEXT" TITLE="setcookie" HREF="function.setcookie.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.header.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.setcookie.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.headers-sent" ></A >headers_sent</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN30555" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >headers_sent -- Checks if or where headers have been sent</DIV ><DIV CLASS="refsect1" ><A NAME="AEN30558" ></A ><H2 >Description</H2 >boolean <B CLASS="methodname" >headers_sent</B > ( [string &file [, int &line]])<BR ></BR ><P > <B CLASS="function" >headers_sent()</B > will return <TT CLASS="constant" ><B >FALSE</B ></TT > if no HTTP headers have already been sent or <TT CLASS="constant" ><B >TRUE</B ></TT > otherwise. If the optional <TT CLASS="parameter" ><I >file</I ></TT > and <TT CLASS="parameter" ><I >line</I ></TT > parameters are set, <B CLASS="function" >headers_sent()</B > will put the php source file name and line number where output started in the <TT CLASS="parameter" ><I >file</I ></TT > and <TT CLASS="parameter" ><I >line</I ></TT > variables. </P ><P > You can't add any more header lines using the <A HREF="function.header.html" ><B CLASS="function" >header()</B ></A > function once the header block has already been sent. Using this function you can at least prevent getting HTTP header related error messages. Another option is to use <A HREF="ref.outcontrol.html" >Output Buffering</A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >New parameters: </B > The optional <TT CLASS="parameter" ><I >file</I ></TT > and <TT CLASS="parameter" ><I >line</I ></TT > parameters where added in PHP 4.3.0. </P ></BLOCKQUOTE ></DIV ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN30587" ></A ><P ><B >Example 1. Examples using <B CLASS="function" >headers_sent()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // If no headers are sent, send one if (!headers_sent()) { header ('Location: http://www.example.com/'); exit; } // An example using the optional file and line parameters, as of PHP 4.3.0 // Note that $filename and $linenum are passed in for later use. // Do not assign them values beforehand. if (!headers_sent($filename, $linenum)) { header ('Location: http://www.example.com/'); exit; // You would most likely trigger an error here. } else { print "Headers already sent in $filename on line $linenum\n" . "Cannot redirect, for now please click this <a " . "href=\"http://www.example.com\">link</a> instead\n"; exit; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > See also <A HREF="function.ob-start.html" ><B CLASS="function" >ob_start()</B ></A >, <A HREF="function.trigger-error.html" ><B CLASS="function" >trigger_error()</B ></A >, and <A HREF="function.header.html" ><B CLASS="function" >header()</B ></A > for a more detailed discussion of the matters involved. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.header.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.setcookie.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >header</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.http.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >setcookie</TD ></TR ></TABLE ></DIV ></BODY ></HTML >