update page now

http_get_last_response_headers

(PHP 8 >= 8.4.0)

http_get_last_response_headersRetrieve last HTTP response headers

Description

http_get_last_response_headers(): ? array

Returns an array containing the last HTTP response headers received via the HTTP wrapper. If there are none, null is returned instead.

Parameters

This function has no parameters.

Return Values

Returns an indexed array of HTTP headers which were received while using the HTTP wrapper. If there are none, null is returned instead.

Examples

Example #1 http_get_last_response_headers() example

Description.

<?php
file_get_contents
("http://example.com");
var_dump(http_get_last_response_headers());
?>

The above example will output something similar to:

array(14) {
 [0]=>
 string(15) "HTTP/1.1 200 OK"
 [1]=>
 string(20) "Accept-Ranges: bytes"
 [2]=>
 string(11) "Age: 326940"
 [3]=>
 string(29) "Cache-Control: max-age=604800"
 [4]=>
 string(38) "Content-Type: text/html; charset=UTF-8"
 [5]=>
 string(35) "Date: 2024年11月11日 13:34:09 GMT"
 [6]=>
 string(23) "Etag: "3147526947+gzip""
 [7]=>
 string(38) "Expires: 2024年11月18日 13:34:09 GMT"
 [8]=>
 string(44) "Last-Modified: 2019年10月17日 07:18:26 GMT"
 [9]=>
 string(24) "Server: ECAcc (nyd/D16C)"
 [10]=>
 string(21) "Vary: Accept-Encoding"
 [11]=>
 string(12) "X-Cache: HIT"
 [12]=>
 string(20) "Content-Length: 1256"
 [13]=>
 string(17) "Connection: close"
}

See Also

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes 1 note

up
0
rene at renux dot de
10 days ago
For PHP versions < 8.4, you can write a polyfill to be prepared for the future:
 
if ( ! function_exists("http_get_last_response_headers") ) {
 function http_get_last_response_headers() {
 if ( ! isset($http_response_header) ) {
 return null;
 }
 return $http_response_header;
 }
}
+add a note

AltStyle によって変換されたページ (->オリジナル) /