php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53018 file_get_contents does not follow 301 and 302 redirects with curlwrappers
Submitted: 2010-10-07 22:43 UTC Modified: 2014-04-25 08:48 UTC
Votes:11
Avg. Score:3.6 ± 1.1
Reproduced:9 of 9 (100.0%)
Same Version:4 (44.4%)
Same OS:4 (44.4%)
From: techs at remsys dot com Assigned: cataphract (profile)
Status: Wont fix Package: cURL related
PHP Version: 5.2.14 OS: Linux x86_64 CentOS release 5.5
Private report: No CVE-ID: None
 [2010-10-07 22:43 UTC] techs at remsys dot com
Description:
------------
Function file_get_contents() does not follow 301 and 302 redirects sub apache module.

It returns following:
--8< -----------------------
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
--8< -----------------------

We got this situation on a 20 servers and even on php-5.2.13, but in the same time it works on others servers with same configuration. 

Mystery starts when we run this script from command line. It works fine with cli, wich is compiled with same options and use same php.ini.


Test script:
---------------
<?php
echo file_get_contents("http://google.com");


Expected result:
----------------
file_get_contents should follow redirects.

Actual result:
--------------
Now it doesn't in some cases.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-08 05:07 UTC] aharvey@php.net
-Status: Open +Status: Feedback
 [2010-10-08 05:07 UTC] aharvey@php.net
The redirections are followed for me both in the CLI and Apache SAPIs; I can't see any obvious reason why one would be different to the other.

Immediate thoughts:

- Does your Apache script set any context options at any point? There is a HTTP context option called "max_redirects" which controls this behaviour -- if it's set to 0, then redirects aren't followed.

- Did either (or both) builds have --with-curlwrappers enabled at build time? You can check that in the "Configure Command" line in phpinfo().
 [2010-10-08 20:27 UTC] techs at remsys dot com
Thank you for reply.
Well same situation with max_redirects. It works only for cli. It seems SAPI ignore it and set to zero or 1.

And yes both versions are comiled with curlwrappers. You can see phpinfo() here 
isonet.ru/test/pi.php


I would really appreciate any other thoughts or suggestions.
Thank you.
 [2010-10-18 17:45 UTC] techs at remsys dot com
-Summary: file_get_contents does not follow 301 and 302 redirects +Summary: file_get_contents does not follow 301 and 302 redirects with curlwrappers -Status: Feedback +Status: Open
 [2010-10-18 17:45 UTC] techs at remsys dot com
As a workaround we have recompiled php without --with-curlwrappers option and file_get_contents started to work as it should.

We have latest curl on that server curl-7.15.5-9.el5 here is version info:
curl 7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
 [2010-10-20 04:31 UTC] cataphract@php.net
-Assigned To: +Assigned To: cataphract
 [2010-10-26 04:21 UTC] cataphract@php.net
-Package: Apache2 related +Package: cURL related
 [2012-12-24 13:49 UTC] pierrick@php.net
cataphract, any idea on how to reproduce this ? or what was the problem ? I'm 
trying to fix as much bug as possible in ext/curl but can not reproduce this one.
 [2013-02-20 02:41 UTC] dev at maliayas dot com
I've had the same bug. My PHP build was compiled with --with-curlwrappers and it didn't follow "Location: " HTTP headers. Then I recompiled it without --with-curlwrappers and it just worked as expected. So the problem must be with the code of Curl Wrapper. After a research, I couldn't find any configuration place for curl wrapper i.e. in php.ini or somewhere else. So the "CURLOPT_FOLLOWLOCATION" setting may be hardcoded with Curl Wrapper to "off". I don't have any further information, just wanted to give some clue.
 [2014-04-25 08:48 UTC] mike@php.net
-Status: Assigned +Status: Wont fix
 [2014-04-25 08:48 UTC] mike@php.net
curlwrappers have been removed in PHP-5.5
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC