Home > Article > Backend Development > How to solve the problem of file_get_contents returning false
Solution to solve the problem that php function file_get_contents returns false:
1. Take a look at these two must-haves in php.ini extension=php_openssl.dll and allow_url_fopen=on are enabled
2. If the above configurations are all enabled, it may be that the service provider has turned off file_get_contents; at this time, only I can write an http request function myself.
Self-written http_request function code, use it directly
/** * 通用CURL请求 * @param $url 需要请求的url * @param null $data * return mixed 返回值 json格式的数据 */ public function http_request($url, $data = null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); if (!empty($data)) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $info = curl_exec($curl); curl_close($curl); return $info; }
Related references:php中文网
The above is the detailed content of How to solve the problem of file_get_contents returning false. For more information, please follow other related articles on the PHP Chinese website!