دالة PHP headers_sent ()
مثال
إذا لم يتم إرسال أي رؤوس ، فأرسل واحدًا:
<?php
if (!headers_sent()) {
header("Location: https://www.w3schools.com/");
exit;
}
?>
<html>
<body>
...
...
التعريف والاستخدام
تتحقق الدالة headers_sent () من / أين تم إرسال الرؤوس.
بناء الجملة
headers_sent(file,line)
قيمه المعامل
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 |
تفاصيل تقنية
قيمة الإرجاع: | تكون القيمة TRUE في حالة إرسال رؤوس HTTP ، وخطأ في الحالات الأخرى |
---|---|
إصدار PHP: | 4.0+ |
سجل التغيير في PHP: | PHP 4.3: تمت إضافة معلمات الملف والخط الاختيارية |
مزيد من الأمثلة
مثال
استخدام معلمات الملف والخط الاختيارية:
<?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