Home > Backend Development > PHP Problem > How to solve the problem that php curl has no return value

How to solve the problem that php curl has no return value

藏色散人
Release: 2023-03-14 13:52:02
Original
6602 people have browsed it

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.

How to solve the problem that php curl has no return value

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[&#39;access_token&#39;]; 
$openid = $json_obj[&#39;openid&#39;]; 
var_dump($res);                                                     //显示obj(false)
echo $openid;
Copy after login

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);  //有返回值
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template