Funkce PHP headers_sent().
Příklad
Pokud nejsou odeslány žádné hlavičky, odešlete jednu:
<?php
if (!headers_sent()) {
header("Location: https://www.w3schools.com/");
exit;
}
?>
<html>
<body>
...
...
Definice a použití
Funkce headers_sent() kontroluje, zda/kam byly odeslány hlavičky.
Syntax
headers_sent(file,line)
Hodnoty parametrů
Parameter | Description |
---|---|
file | Optional. If the file and line parameters are set, headers_sent() will put the PHP source file name and line number where output started in the file and line variables |
line | Optional. Specifies the line number where the output started |
Technické údaje
Návratová hodnota: | PRAVDA, pokud byla odeslána záhlaví HTTP, jinak NEPRAVDA |
---|---|
Verze PHP: | 4,0+ |
PHP Changelog: | PHP 4.3: Přidány volitelné parametry souboru a řádku |
Další příklady
Příklad
Pomocí volitelných parametrů souboru a řádku:
<?php
// $file and $line are passed in for later use
// Do not assign them values beforehand
if (!headers_sent($file, $line))
{
header("Location: https://www.w3schools.com/");
exit;
// Trigger an error here
}
else
{
echo "Headers sent in $file on line $line";
exit;
}
?>
<html>
<body>
...
...
❮ Síťová reference PHP