What are some potential pitfalls when using file_get_contents for handling redirects in PHP?

When using file_get_contents to handle redirects in PHP, one potential pitfall is that it does not automatically follow HTTP redirects. To solve this, you can use the stream context options to enable following redirects by setting the 'follow_location' option to true.

$url = 'http://example.com';
$options = [
    'http' => [
        'follow_location' => 1
    ]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
echo $response;