php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49066 CURLOPT_FAILONERROR does not work when CURLOPT_FOLLOWLOCATION is true
Submitted: 2009-07-26 16:01 UTC Modified: 2009-08-03 23:03 UTC
From: peaceable_whale at hotmail dot com Assigned:
Status: Not a bug Package: cURL related
PHP Version: 5.*, 6SVN (2009-08-04) OS: *
Private report: No CVE-ID: None
 [2009-07-26 16:01 UTC] peaceable_whale at hotmail dot com
Description:
------------
CURLOPT_FAILONERROR does not work when CURLOPT_URL is reset. Not false is returned even when the response code is >=400.

Reproduce code:
---------------
<?php
header("Content-Type: text/plain; charset=UTF-8");
header("X-Content-Type-Options: nosniff");
$request=curl_init();
curl_setopt_array($request,array(CURL_HTTP_VERSION_1_1=>true,CURLOPT_USERAGENT=>"PHP/".phpversion(),CURLOPT_FAILONERROR=>false,CURLOPT_RETURNTRANSFER=>true));
for($i=0;$i<5;$i++) {
	curl_setopt($request,CURLOPT_URL,"http://example.com/".$i);
	echo "Trial ".$i.": ".(curl_exec($request)===false?"false":"true")."\r\n";
}
curl_close($request);
?>

Expected result:
----------------
Trial 0: false
Trial 1: false
Trial 2: false
Trial 3: false
Trial 4: false

Actual result:
--------------
Trial 0: true
Trial 1: true
Trial 2: true
Trial 3: true
Trial 4: true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-26 16:16 UTC] peaceable_whale at hotmail dot com
The previous submitted code doesn't reflect the problem correctly... The followings are the corrected information:

Description:
------------
CURLOPT_FAILONERROR does not work when CURLOPT_FOLLOWLOCATION is true and open_dir is set.

PHP Version:
------------
PHP 5.3.0 NTS VC9

Reproduce code:
---------------
<?php
error_reporting(E_ALL^E_WARNING);
header("Content-Type: text/plain; charset=UTF-8");
header("X-Content-Type-Options: nosniff");
$request=curl_init("http://example.com/X");
curl_setopt_array($request,array(CURL_HTTP_VERSION_1_1=>true,CURLOPT_USERAGENT=>"PHP/".phpversion(),CURLOPT_FOLLOWLOCATION=>true,CURLOPT_FAILONERROR=>true,CURLOPT_RETURNTRANSFER=>true));
echo (curl_exec($request)===false?"false":"true")."\r\n";
curl_close($request);
?>

Expected result:
----------------
false

Actual result:
--------------
true)
 [2009-08-03 22:54 UTC] jani@php.net
A bit more readable script:

<?php
error_reporting(E_ALL^E_WARNING);
$request=curl_init("http://example.com/X");
curl_setopt_array($request,
        array(
                CURL_HTTP_VERSION_1_1  => true,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_FAILONERROR    => true,
                CURLOPT_RETURNTRANSFER=>true,
        )
);

var_dump(curl_exec($request));

?>

To reproduce:

# sapi/cli/php -n -dopen_basedir=. test.php



 [2009-08-03 22:55 UTC] jani@php.net
To be clear: without open_basedir it works fine.
 [2009-08-03 23:03 UTC] jani@php.net
And the reason this fails is found on the manual page for 
curl_setopt_array():

"Returns TRUE if all options were successfully set. If an option could 
not be successfully set, FALSE is immediately returned, ignoring any 
future options in the options array."

And this error is output when you don't disable errors:

Warning: curl_setopt_array(): CURLOPT_FOLLOWLOCATION cannot be activated 
when in safe_mode or an open_basedir is set..

There is no bug here.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC