How can you access and evaluate the header of a redirect in PHP?

When a redirect occurs in PHP, you may need to access and evaluate the headers of the redirect response for various reasons, such as checking the status code or extracting specific header values. To do this, you can use the PHP function get_headers() to retrieve an array of headers from the specified URL. You can then loop through the array to access and evaluate the headers as needed.

// Specify the URL of the redirect
$url = 'http://example.com';

// Get the headers of the redirect URL
$headers = get_headers($url, 1);

// Loop through the headers array to access and evaluate the headers
foreach($headers as $key => $value) {
    echo $key . ': ' . $value . '<br>';
}