Skip to content

Instantly share code, notes, and snippets.

@vgrovestine
Created October 6, 2021 17:47
Show Gist options
  • Save vgrovestine/35fd7256ee1c97d60901d33cc3bad511 to your computer and use it in GitHub Desktop.
Save vgrovestine/35fd7256ee1c97d60901d33cc3bad511 to your computer and use it in GitHub Desktop.
Alternative to file_get_contents() which uses curl to get around remote SSL certificate snags
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
// curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment