go to bug id or search bugs for
i set 'max_redirects' to 1 to disable redirect, but it did not work and produce some error....
'PHP Warning: fopen(): Redirection limit reached, aborting. in D:\webroot\nlr.ph
p on line 66'
if i set it to 2, everything works well...redirect works.
note: http://172.23.68.8/index.php will simple locate to another url.
$access = "http://172.23.68.8/index.php";
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Accept: */*\r\n" .
"Accept-Language: en-us\r\n" .
"Accept-Encoding: gzip, deflate\r\n" .
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)\r\n" .
//"Host: www.netlibrary.com\r\n" .
'max_redirects' => '1'
$context = stream_context_create($opts);
$fp = fopen($access, 'r', false, $context);
$meta_data = stream_get_meta_data($fp);
PHP Warning: fopen(): Redirection limit reached, aborting. in D:\webroot\nlr.ph
p on line 66
Warning: fopen(): Redirection limit reached, aborting. in D:\webroot\nlr.php on
PHP Warning: fopen(http://172.23.68.8/index.php): failed to open stream: No err
or in D:\webroot\nlr.php on line 66
Warning: fopen(http://172.23.68.8/index.php): failed to open stream: No error in
D:\webroot\nlr.php on line 66
PHP Warning: stream_get_meta_data(): supplied argument is not a valid stream re
source in D:\webroot\nlr.php on line 67
Warning: stream_get_meta_data(): supplied argument is not a valid stream resourc
e in D:\webroot\nlr.php on line 67
PHP Warning: fclose(): supplied argument is not a valid stream resource in D:\w
ebroot\nlr.php on line 70
Warning: fclose(): supplied argument is not a valid stream resource in D:\webroo
t\nlr.php on line 70
Add a Patch
Add a Pull Request
max_redirects - The max number of redirects to follow. Value 1 or less means that no redirects are followed.
i see, no redirects followed, but it didn't fetch any info(headers) from the first request.
it produce error "Redirection limit reached", i just need the first header.
sorry for poor english.;)
i just want get first hrader and not let php automatic follow the redirect.
i try again and it did not work.
The first header is "Location", this is pretty clear.
If you want to get the header itself you can use fsockopen().
I get the same error if I just want to download the mirror selection page:
file_put_contents('xampp-win32-1.6.4.exe.html', file_get_contents('http://downloads.sourceforge.net/xampp/xampp-win32-1.6.4.exe?use_mirror=osdn', FALSE, stream_context_create(array('http'=>array('max_redirects'=>1))), 0, 10000));
There's a small gap of proper support here:
1) the get_headers() function would give the Location header (since it uses STREAM_ONLY_GET_HEADERS) if the max_redirects is set to 1, but it doesn't return a response body
2) the current fopen wrapper function only returns the headers (inside the wrapper data) in the absence of a Location header
I was exploring to use php streams as an extension to the oauth project so that the curl dependency could be made optional, but this would require me to copy & paste a lot of logic from php_stream_url_wrap_http_ex() =(
To be documented: (Tip?): use ignore_errors=1 and max_redirects=0 to never follow redirects while being able to get headers and response body.
Proposed patch: http://codepad.org/DoeR65RJ
Automatic comment from SVN on behalf of joey
Log: Apply user-patch from David Tajchreber, closes PHP Bug #38802
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
Related To: Bug #70039