Example 1 — Read Headers After an HTTP Wrapper Call
Show the PHP 8.4 getter shape. The printed lines are a typical sample after fetching https://example.com.
<?php
if (!function_exists("http_get_last_response_headers")) {
echo "needs PHP 8.4+", PHP_EOL;
exit;
}
// file_get_contents("https://example.com");
// $headers = http_get_last_response_headers();
$headers = [
"HTTP/1.1 200 OK",
"Content-Type: text/html; charset=UTF-8",
];
foreach ($headers as $line) {
echo $line, PHP_EOL;
} How It Works
- A real script would call file_get_contents() on an http(s) URL first.
- http_get_last_response_headers() would then return the response header lines.
- This demo prints a fixed sample of those lines for View Output.
- Index 0 is usually the HTTP status line.

