php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38802 'max_redirects' context options doesn't work when value is 1
Submitted: 2006-09-13 07:36 UTC Modified: 2010-02-17 00:35 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (66.7%)
From: datibbaw@php.net Assigned:
Status: Closed Package: HTTP related
PHP Version: 5.2.9 OS: Linux Gentoo
Private report: No CVE-ID: None
 [2006-09-13 07:36 UTC] datibbaw@php.net
Description:
------------
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.


;)
thanks

SHEN ZhiQiang

Reproduce code:
---------------
$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" .
					"Connection: Keep-Alive\r\n",
	'max_redirects' => '1'
	)
);

$context = stream_context_create($opts);

$fp = fopen($access, 'r', false, $context);
$meta_data = stream_get_meta_data($fp);
var_dump($meta_data);
file_put_contents('./test.dump', $fp);
fclose($fp);

Actual result:
--------------
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
line 66
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
bool(false)
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-13 08:04 UTC] tony2001@php.net
max_redirects - The max number of redirects to follow. Value 1 or less means that no redirects are followed. 

http://www.php.net/manual/en/wrappers.http.php
 [2006-09-13 10:11 UTC] shen dot shenstone at gmail dot com
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.

thanks
sorry for poor english.;)
 [2006-09-13 12:44 UTC] shen dot shenstone at gmail dot com
i just want get first hrader and not let php automatic follow the redirect.

i try again and it did not work.

;(

thanks
 [2006-09-13 12:54 UTC] tony2001@php.net
The first header is "Location", this is pretty clear.
If you want to get the header itself you can use fsockopen().

 [2007-10-08 11:20 UTC] rele at gmx dot de
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));
 [2009-05-11 14:51 UTC] datibbaw@php.net
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() =(
 [2009-05-16 20:54 UTC] lbarnaud@php.net
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.
 [2010-01-17 23:15 UTC] dave dot tajchreber at gmail dot com
Proposed patch: http://codepad.org/DoeR65RJ

David Tajchreber
 [2010-02-17 00:35 UTC] svn@php.net
Automatic comment from SVN on behalf of joey
Revision: http://svn.php.net/viewvc/?view=revision&revision=295190
Log: Apply user-patch from David Tajchreber, closes PHP Bug #38802
 [2010-02-17 00:35 UTC] joey@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC