PHP headers_sent() İşlevi
Örnek
Hiçbir başlık gönderilmediyse, bir tane gönderin:
<?php
if (!headers_sent()) {
header("Location: https://www.w3schools.com/");
exit;
}
?>
<html>
<body>
...
...
Tanım ve Kullanım
headers_sent() işlevi, başlıkların gönderilip gönderilmediğini/nerede olduğunu kontrol eder.
Sözdizimi
headers_sent(file,line)
Parametre Değerleri
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 |
Teknik detaylar
Geri dönüş değeri: | HTTP üstbilgileri gönderildiyse DOĞRU, aksi takdirde YANLIŞ |
---|---|
PHP Sürümü: | 4.0+ |
PHP Değişiklik Günlüğü: | PHP 4.3: İsteğe bağlı dosya ve satır parametreleri eklendi |
Daha fazla örnek
Örnek
İsteğe bağlı dosya ve satır parametrelerini kullanarak:
<?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 Ağ Referansı