curl_error


php128 apg

RETURN the last cURL error name as string.


<?php

string curl_error
(CurlHandle $handle);


where,

$handle The cURL handle returned by curl_init function
  
?>

 $handle 


The cURL handle returned by curl_init function.


  1 EXERCISE   

<?php

// Create a curl handle to a non-existing location
$ch curl_init('http://404.php.net/');
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

if(
curl_exec($ch) === false)
{
    echo 
'Curl error: ' curl_error($ch);
}
else
{
    echo 
'Operation completed without any errors';
}

// Close handle
curl_close($ch);

?>

 RESULT   

Curl error: Could not resolve host: 404.php.net

  2 EXERCISE   

<?php

// Create a curl handle to a non-existing location
$ch curl_init('https://www.php.net/');
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

if(
curl_exec($ch) === false)
{
    echo 
'Curl error: ' curl_error($ch);
}
else
{
    echo 
'Operation completed without any errors';
}

// Close handle
curl_close($ch);

?>

 RESULT   

Operation completed without any errors