I have written this simple piece of code :
$ch = curl_init();
//Set options
curl_setopt($ch, CURLOPT_URL, "http://www.php.net");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$website_content = curl_exec ($ch);
In my case $website_content comes as false.
Can anyone suggest/advice something what could be going wrong?
Error checking and handling is the programmer’s friend. Check the return values of the initializing and executing cURL functions.
curl_error()andcurl_errno()will contain further information in case of failure:* The
curl_init()manual states:I’ve observed the function to return
FALSEwhen you’re using its$urlparameter and the domain could not be resolved. If the parameter is unused, the function might never returnFALSE. Always check it anyways, though, since the manual doesn’t clearly state what "errors" actually are.