MuteX
MuteX

Reputation: 183

Curl_exec return null in php

I have a problem to get the data using curl operation. Here i hide the token, If i use the url only in my browser then it returns the data but here its null.

<?php 
$token = "TOKEN"; //the actual token hidden
$url = "https://crm.zoho.com/crm/private/xml/Leads/getRecords?authtoken=".$token."&scope=crmapi";
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);

$result = curl_exec($ch);
curl_close($ch);
echo $result; //does not return anything
?>

Where i do mistake please help me.

Upvotes: 11

Views: 43021

Answers (3)

Jeff Wang
Jeff Wang

Reputation: 183

please see below article , not just turn off verify , you should update your php.ini with pem file

https://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/

Anyone running a recent Linux distribution is probably already OK, because they get the curl libraries bundled in through their package managers and recent curl libraries come with the latest CA root certificate bundle from Mozilla.org.

For a PHP installation that doesn’t come with this file, like the Windows PHP distribution, you need to download the CA root certificate bundle and tell PHP where to find it.

Upvotes: 0

Ayyanar G
Ayyanar G

Reputation: 1545

Try adding these lines:

<?php 
$token = "TOKEN"; //the actual token hidden
$url = "https://crm.zoho.com/crm/private/xml/Leads/getRecords";
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("authtoken"=>$token,"scope"=>"crmapi"));
$result = curl_exec($ch);
curl_close($ch);
echo $result; //does not return anything
?>

Upvotes: 0

jogesh_pi
jogesh_pi

Reputation: 9782

This is how you can try with CURLOPT_RETURNTRANSFER which is used to return the output and curl_errno() to track the errors :

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://example.com/my_url.php" ); 
curl_setopt($ch, CURLOPT_POST, 1 ); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$postResult = curl_exec($ch); 

if (curl_errno($ch)) { 
   print curl_error($ch); 
} 
curl_close($ch); 

Helpful Links: curl_errno(), curl_error()

Upvotes: 17

Related Questions