How to get file_get_contents() to work with HTTPS? How to get file_get_contents() to work with HTTPS? curl curl

How to get file_get_contents() to work with HTTPS?


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.dllallow_url_fopen = On


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: yeshttp wrapper: yeshttps wrapper: yeswrappers: array(11) {  [...]}


$url= 'https://example.com';$arrContextOptions=array(      "ssl"=>array(            "verify_peer"=>false,            "verify_peer_name"=>false,        ),    );  $response = file_get_contents($url, false, stream_context_create($arrContextOptions));

This will allow you to get the content from the url whether it is a HTTPS