PHP headers_sent() Functie
Voorbeeld
Als er geen headers worden verzonden, stuur er dan een:
<?php
if (!headers_sent()) {
header("Location: https://www.w3schools.com/");
exit;
}
?>
<html>
<body>
...
...
Definitie en gebruik
De functie headers_sent() controleert of/waar headers zijn verzonden.
Syntaxis
headers_sent(file,line)
Parameterwaarden
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 |
Technische details
Winstwaarde: | TRUE als HTTP-headers zijn verzonden, anders FALSE |
---|---|
PHP-versie: | 4.0+ |
PHP-wijzigingslogboek: | PHP 4.3: de optionele bestands- en regelparameters toegevoegd |
Meer voorbeelden
Voorbeeld
De optionele bestands- en regelparameters gebruiken:
<?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>
...
...
❮ PHP-netwerkreferentie