I would like to know if its possible to clear the current information stored in header_list()
if(headers_sent()){
foreach(headers_list() as $header){
header_remove($header);
}
}
var_dump(headers_list());
if you want to remove header information about php version (x-powered-by), you can use: header_remove('x-powered-by');
The header_remove() function removes an HTTP header previously set with the header() function.
There is an easy way to hide the PHP version from the HTTP headers. By setting the “expose_php” variable to Off in your php. ini file the PHP version would not longer be added to the HTTP headers.
The get_headers() function in PHP is used to fetch all the headers sent by the server in the response of an HTTP request. Parameters: This function accepts three parameters as mentioned above and described below: $url: It is a mandatory parameter of type string.
headers_sent
indicates that it is too late to remove headers. They're already sent. Hence the name of the function.
What you want is to specifically check if the headers have not been sent yet. Then you know it's safe to modify them.
if (!headers_sent()) {
foreach (headers_list() as $header)
header_remove($header);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With