从5.1.0版开始,就有
max_redirects option
Location
重定向:
要遵循的最大重定向数。值1或更小表示不遵循重定向。
您可能需要显式地设置它,以防您的配置禁用它。根据文档修改的示例:
<?php
$url = 'http://www.example.com/';
$opts = array(
'http' => array('method' => 'GET',
'max_redirects' => '20')
);
$context = stream_context_create($opts);
$stream = fopen($url, 'r', false, $context);
// header information as well as meta data
// about the stream
var_dump(stream_get_meta_data($stream));
// actual data at $url
var_dump(stream_get_contents($stream));
fclose($stream);
?>