Skip to content

Instantly share code, notes, and snippets.

@mistergraphx
Created June 8, 2015 08:55
Show Gist options
  • Save mistergraphx/d84a0ae6eca294393e7e to your computer and use it in GitHub Desktop.
Save mistergraphx/d84a0ae6eca294393e7e to your computer and use it in GitHub Desktop.
Suivant la configuration serveur, utiliser : - curl - file_get_content - fopen From http://stackoverflow.com/questions/3979802/alternative-to-file-get-contents
//function to get the remote data
function url_get_contents ($url) {
if (function_exists('curl_exec')){
$conn = curl_init($url);
curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($conn, CURLOPT_FRESH_CONNECT, true);
curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);
$url_get_contents_data = (curl_exec($conn));
curl_close($conn);
}elseif(function_exists('file_get_contents')){
$url_get_contents_data = file_get_contents($url);
}elseif(function_exists('fopen') && function_exists('stream_get_contents')){
$handle = fopen ($url, "r");
$url_get_contents_data = stream_get_contents($handle);
}else{
$url_get_contents_data = false;
}
return $url_get_contents_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment