What is the meaning of the parameters of the function headers_sent()?

<?php

// If not sent a single header, send one
if (!headers_sent()) {
 header('Location: http://www.example.com/');
exit;
}

// Example of using optional parameters file and line.
// It should be noted that $filename and $linenum are passed in for later use.
// Do not assign them values beforehand.
if (!headers_sent($filename, $linenum)) {
 header('Location: http://www.example.com/');
exit;

// Most likely, the error will occur here.
} else {

 echo "Headers were already sent in $filename at line $linenum\n" .
 "Cannot redirect, please go on this <a" .
"href=\"http://www.example.com\">link</a>\n";
exit;
}

?>

For example here in any case, either $linenum=0 and $filename = "" or triggered the header and redirects us to the website
and why do we need designif (!headers_sent($filename, $linenum))
if in any case, after the header - we're on a different page, why do something after the header?
April 4th 20 at 00:51
1 answer
April 4th 20 at 00:53
Solution
not just header redirects to another page, and can add additional headers content-type for example, etc. And if the headers are already sent, all. The same applies to session_start () must be invoked prior to transmission of the headers
<?php
header('WWW-Authenticate: Negotiate');
headers_sent($filename, $linenum);
echo "$filename <br>" . "$linenum";
exit;

?>

there is also $linenum=0 and $filename = "", so I thought. other headers not working in php - kayli76 commented on April 4th 20 at 00:56
In php there are contradictory things, but completely useless - unlikely) - Einar.Barro commented on April 4th 20 at 00:59
session_start () must be invoked prior to transmission

No, you can send any number of headers, even if some were sent, you can't put the headers only if you have already sent something in the response body. - Nat.Goldner commented on April 4th 20 at 01:02
@Nat.Goldner, that is simply called any response header? - kayli76 commented on April 4th 20 at 01:05
@Einar.Barro, well, why go to answer if you do not understand the question?

Author, why did you mark the answer if he does not that?
What I sense now to write a normal response if the question is already garbage? - rae.Breitenber commented on April 4th 20 at 01:08
@rae.Breitenber, excuse me, your Majesty - Einar.Barro commented on April 4th 20 at 01:11
as you say - rae.Breitenber commented on April 4th 20 at 01:14
@rae.Breitenber, I really do not understand your claims. If the author said the answer the answer is, that it is satisfied. I've only been here a couple of days, but if all the answers it is better to leave you, I will leave. I said weird, but still answered in the context of another question that the author asked before. I of these two issues it seemed that the author decided that header() is used only for the redirect, and answered. I don't see why you instead attack me and the author just write a good answer - Einar.Barro commented on April 4th 20 at 01:17
I'm sorry, I inattentively read a question. Indeed, there turns out to be the whole point of the last line. - rae.Breitenber commented on April 4th 20 at 01:20
@rae.Breitenber, unexpectedly, thank you) - Einar.Barro commented on April 4th 20 at 01:23

Find more questions by tags PHP