PHP | headers_list() Function
Last Updated :
31 Jan, 2019
The header_list() function is an inbuilt function in PHP which returns the list of response header that sent or ready to send to the client or browser, in the form of array.
Syntax:
array headers_list( void )
Parameters: This function does not accept any parameter.
Return Value: It returns a list or array of headers to be sent to the browser or client.
Note: It differs from headers_sent() function which is suitable to check whether the header sent or not but headers_list() is not favorable in this context as it lists both sent and ready to send states of headers.
Example 1:
<?php
setcookie( "cookie1" , "value_of_cookie1" );
header( "test: geeksforgeeks" );
header( "Content-type: text/plain" );
print_r(headers_list());
?>
|
Output:
Array
(
[0] => Set-Cookie: cookie1=value_of_cookie1
[1] => test: geeksforgeeks
[2] => Content-type: text/plain;charset=UTF-8
)
Example 2:
<?php
setcookie( 'uid' , 'user4059' );
header( "custom-res-header: cstm" );
header( 'Content-type: text/plain' );
var_dump(headers_list());
?>
|
Output:
array(3) {
[0]=>string(24) "Set-Cookie: uid=user4059"
[1]=>string(23) "custom-res-header: cstm"
[2]=>string(38) "Content-type: text/plain;charset=UTF-8"
}
Reference: http://php.net/manual/en/function.headers-list.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...