PHP headers_sent() Fungsi
Contoh
Jika tidak ada tajuk yang dikirim, kirim satu:
<?php
if (!headers_sent()) {
header("Location: https://www.w3schools.com/");
exit;
}
?>
<html>
<body>
...
...
Definisi dan Penggunaan
Fungsi headers_sent() memeriksa apakah/di mana header telah dikirim.
Sintaksis
headers_sent(file,line)
Nilai Parameter
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 |
Detail Teknis
Nilai Kembali: | BENAR jika header HTTP telah dikirim, SALAH jika sebaliknya |
---|---|
Versi PHP: | 4.0+ |
Log Perubahan PHP: | PHP 4.3: Menambahkan file opsional dan parameter baris |
Lebih Banyak Contoh
Contoh
Menggunakan file opsional dan parameter baris:
<?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>
...
...
Referensi Jaringan PHP