Home >Backend Development >PHP Problem >How to solve the problem that php curl has no return value
php curl has no return value solution: 1. Open the corresponding PHP code file; 2. Solve it through the "curl_setopt($ch,CURLOPT_URL,$get_token_url);curl_setopt();..." code Can.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to solve the problem that php curl has no return value?
php uses curl to access https and returns no results
Recently I am doing a WeChat automatic After logging in and initiating verification, the curl function returns empty when the page is called back to obtain the openid.
$appid = "appid appid "; $secret = "secret "; $code = $_GET["code"]; $get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code'; //header("location:$get_token_url"); echo $get_token_url."<BR>"; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$get_token_url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1 ); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); $res = curl_exec($ch); echo "echo:".json_encode($res)."<br>"; //显示false echo curl_multi_getcontent($ch)."<br>"; //空 curl_close($ch); $json_obj = json_decode($res,true); //根据openid和access_token查询用户信息 $access_token = $json_obj['access_token']; $openid = $json_obj['openid']; var_dump($res); //显示obj(false) echo $openid;
As a result, curl has no return value. Finally, Baidu found an article http://yanda.net.cn/articles/453. The
mentioned in the article was changed to the following Problem Solving
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$get_token_url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1 ); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); $res = curl_exec($ch); var_dump($res); //有返回值
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to solve the problem that php curl has no return value. For more information, please follow other related articles on the PHP Chinese website!