How to solve the problem of file_get_contents returning false

WJ
Release: 2023-03-01 11:12:02
forward
6074 people have browsed it

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;
    }
Copy after login

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!

Related labels:
php
source:51dev.com
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