<?php
header('Content-Type: application/json');

$headers = [];
foreach ($_SERVER as $name => $value) {
    if (substr($name, 0, 5) == 'HTTP_') {
        $headers[$name] = $value;
    }
}

// Also try getallheaders() if available
if (function_exists('getallheaders')) {
    $headers['getallheaders_output'] = getallheaders();
}

echo json_encode($headers, JSON_PRETTY_PRINT);
?>