PHP हेडर_सेंट () फ़ंक्शन
उदाहरण
यदि कोई हेडर नहीं भेजा जाता है, तो एक भेजें:
<?php
if (!headers_sent()) {
header("Location: https://www.w3schools.com/");
exit;
}
?>
<html>
<body>
...
...
परिभाषा और उपयोग
हेडर_सेंट () फ़ंक्शन जांचता है कि हेडर भेजे गए हैं या नहीं।
वाक्य - विन्यास
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 शीर्षलेख भेजे गए हैं, अन्यथा FALSE |
---|---|
पीएचपी संस्करण: | 4.0+ |
पीएचपी चेंजलॉग: | 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>
...
...
पीएचपी नेटवर्क संदर्भ