Does fopen automatically follow the Location Header in PHP?
When using fopen in PHP to open a URL, it does not automatically follow the Location Header if a redirect is returned. To make fopen automatically follow the Location Header and handle redirects, you can use the stream context options with the 'http' key set to follow_location => 1.
$context = stream_context_create(['http' => ['follow_location' => 1]]);
$file = fopen('http://example.com', 'r', false, $context);