<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.network.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.headers-sent.php',
    1 => 'headers_sent',
    2 => 'Checks if or where headers have been sent',
  ),
  'up' => 
  array (
    0 => 'ref.network.php',
    1 => 'Network Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.headers-list.php',
    1 => 'headers_list',
  ),
  'next' => 
  array (
    0 => 'function.http-clear-last-response-headers.php',
    1 => 'http_clear_last_response_headers',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/network/functions/headers-sent.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.headers-sent" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">headers_sent</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">headers_sent</span> &mdash; <span class="dc-title">Checks if or where headers have been sent</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.headers-sent-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>headers_sent</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter reference">&$filename</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter reference">&$line</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Checks if or where headers have been sent.
  </p>
  <p class="para">
   You can&#039;t add any more header lines using the <span class="function"><a href="function.header.php" class="function">header()</a></span>
   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.php" class="link">Output Buffering</a>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.headers-sent-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       If the optional <code class="parameter">filename</code> and
       <code class="parameter">line</code> parameters are set, 
       <span class="function"><strong>headers_sent()</strong></span> will put the PHP source file name
       and line number where output started in the <code class="parameter">filename</code>
       and <code class="parameter">line</code> variables.
      </p>
      <blockquote class="note"><p><strong class="note">Nota</strong>: 
       <p class="para">
        If the output has started before executing the PHP source file (for example due to a startup error),
        the <code class="parameter">filename</code> parameter will be set to an empty string.
       </p>
      </p></blockquote>
     </dd>
    
    
     <dt><code class="parameter">line</code></dt>
     <dd>
      <p class="para">
       The line number where the output started.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.headers-sent-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   <span class="function"><strong>headers_sent()</strong></span> will return <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if no HTTP headers
   have already been sent or <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> otherwise.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.headers-sent-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Examples using <span class="function"><strong>headers_sent()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// If no headers are sent, send one<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">headers_sent</span><span style="color: #007700">()) {<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Location: http://www.example.com/'</span><span style="color: #007700">);<br />    exit;<br />}<br /><br /></span><span style="color: #FF8000">// An example using the optional file and line parameters<br />// Note that $filename and $linenum are passed in for later use.<br />// Do not assign them values beforehand.<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">headers_sent</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">, </span><span style="color: #0000BB">$linenum</span><span style="color: #007700">)) {<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Location: http://www.example.com/'</span><span style="color: #007700">);<br />    exit;<br /><br /></span><span style="color: #FF8000">// You would most likely trigger an error here.<br /></span><span style="color: #007700">} else {<br /><br />    echo </span><span style="color: #DD0000">"Headers already sent in </span><span style="color: #0000BB">$filename</span><span style="color: #DD0000"> on line </span><span style="color: #0000BB">$linenum</span><span style="color: #DD0000">\n" </span><span style="color: #007700">.<br />          </span><span style="color: #DD0000">"Cannot redirect, for now please click this &lt;a " </span><span style="color: #007700">.<br />          </span><span style="color: #DD0000">"href=\"http://www.example.com\"&gt;link&lt;/a&gt; instead\n"</span><span style="color: #007700">;<br />    exit;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 notes" id="refsect1-function.headers-sent-notes">
  <h3 class="title">Note</h3>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
   Gli header sono accessibili (e emessi nell&#039;output) quando è in uso un SAPI che
   li supporta.
   </p>
  </p></blockquote>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.headers-sent-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.ob-start.php" class="function" rel="rdfs-seeAlso">ob_start()</a> - Turn on output buffering</span></li>
    <li><span class="function"><a href="function.trigger-error.php" class="function" rel="rdfs-seeAlso">trigger_error()</a> - Genera un messaggio a livello utente di errore/avviso/avvertimento message</span></li>
    <li><span class="function"><a href="function.headers-list.php" class="function" rel="rdfs-seeAlso">headers_list()</a> - Returns a list of response headers sent (or ready to send)</span></li>
    <li>
     <span class="function"><a href="function.header.php" class="function" rel="rdfs-seeAlso">header()</a> - Send a raw HTTP header</span> for a more detailed discussion of the
     matters involved.
    </li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>