Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that php curl does not return a value?

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to solve the problem that there is no return value in php curl". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Php curl does not return a value solution: 1, open the corresponding PHP code file; 2, through "curl_setopt ($ch,CURLOPT_URL,$get_token_url); curl_setopt ();..." The code can be solved.

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.

How to solve the problem that php curl does not return a value?

Php uses curl to access https and returns no result.

Recently, after automatically logging in to Wechat, the curl function returned null when the page was called back to get openid after initiating verification.

$appid = "appid appid"; $secret = "secret"; $code = $_ GET ["code"]; $get_token_url = 'https://api.weixin.qq.com/sns/oauth3/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code';//header("location:$get_token_url");echo $get_token_url. "

"; $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)."

"; / / display falseecho curl_multi_getcontent ($ch)."

"; / / empty curl _ close ($ch); $json_obj = json_decode ($res,true); / / query user information based on openid and access_token $access_token = $json_obj ['access_token']; $openid = $json_obj [' openid']; var_dump ($res); / / display obj (false) echo $openid

As a result, there was no return value for curl. Finally, Baidu mentioned it in an article http://yanda.net.cn/articles/453.

Change it to the following problem solution

$ch = curl_init (); curl_setopt ($ch,CURLOPT_URL,$get_token_url); curl_setopt ($ch,CURLOPT_HEADER,0); curl_setopt ($ch,CURLOPT_ SSL_VERIFYPEER, false); / / do not verify certificate curl_setopt ($ch,CURLOPT_ SSL_VERIFYHOST, false); / / do not verify certificate curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,10); $res = curl_exec ($ch); var_dump ($res) / / this is the end of the return value "how to solve the problem of no return value in php curl". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report