How to get file_get_contents() to work with HTTPS?

后端 未结 12 1953
长发绾君心
长发绾君心 2020-11-21 23:38

I\'m working on setting up credit card processing and needed to use a workaround for CURL. The following code worked fine when I was using the test server (which wasn\'t cal

相关标签:
12条回答
  • 2020-11-22 00:17

    Just add two lines in your php.ini file.

    extension=php_openssl.dll

    allow_url_include = On

    its working for me.

    0 讨论(0)
  • 2020-11-22 00:18

    In my case, the issue was due to WAMP using a different php.ini for CLI than Apache, so your settings made through the WAMP menu don't apply to CLI. Just modify the CLI php.ini and it works.

    0 讨论(0)
  • 2020-11-22 00:18

    Sometimes a server will choose not to respond based on what it sees or doesn't see in the http request headers (such as an appropriate user agent). If you can connect with a browser, grab the headers it sends and mimic them in your stream context.

    0 讨论(0)
  • 2020-11-22 00:30

    I had the same error. Setting allow_url_include = On in php.ini fixed it for me.

    0 讨论(0)
  • 2020-11-22 00:31

    To allow https wrapper:

    • the php_openssl extension must exist and be enabled
    • allow_url_fopen must be set to on

    In the php.ini file you should add this lines if not exists:

    extension=php_openssl.dll
    
    allow_url_fopen = On
    
    0 讨论(0)
  • 2020-11-22 00:32

    Try the following script to see if there is an https wrapper available for your php scripts.

    $w = stream_get_wrappers();
    echo 'openssl: ',  extension_loaded  ('openssl') ? 'yes':'no', "\n";
    echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
    echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
    echo 'wrappers: ', var_export($w);
    

    the output should be something like

    openssl: yes
    http wrapper: yes
    https wrapper: yes
    wrappers: array(11) {
      [...]
    }
    
    0 讨论(0)
提交回复
热议问题