What are the potential pitfalls of using get_headers() to retrieve HTTP headers, especially when dealing with redirects?

When using get_headers() to retrieve HTTP headers, one potential pitfall is that it does not follow redirects by default. This means that if a URL redirects to another location, get_headers() will only return the headers of the initial response, not the final destination. To retrieve headers after following redirects, you can set the "stream_context" parameter to follow redirects using the "http" context options.

$url = 'http://example.com';
$options = stream_context_create(['http' => ['follow_location' => 1]]);
$headers = get_headers($url, 0, $options);

foreach ($headers as $header) {
    echo $header . "\n";
}