|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 15:00:01 2025 UTC |
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)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