Added a couple examples.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@102832 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2002-11-07 01:29:44 +00:00
parent 124b7f5e32
commit aaf30477a2

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- $Revision: 1.9 $ -->
<!-- splitted from ./en/functions/http.xml, last change in rev 1.7 -->
<refentry id="function.headers-sent">
<refnamediv>
@ -34,8 +34,42 @@
</simpara>
</note>
<para>
See also <function>ob_start</function> and <function>header</function> for a
more detailed discussion of the matters involved.
<example>
<title>Examples using <function>headers_sent</function></title>
<programlisting role="php">
<![CDATA[
<?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";
print "Cannot redirect, for now please click this $link instead\n";
exit;
}
?>
]]>
</programlisting>
</example>
</para>
<para>
See also <function>ob_start</function>, <function>trigger_error</function>,
and <function>header</function> for a more detailed discussion of the
matters involved.
</para>
</refsect1>
</refentry>