Skip to content

Instantly share code, notes, and snippets.

@sagive
Created January 20, 2015 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagive/5938ab5561c1a54606b3 to your computer and use it in GitHub Desktop.
Save sagive/5938ab5561c1a54606b3 to your computer and use it in GitHub Desktop.
Simple Curl Example
function curl_download($url, $referer, $browserAgent){
if (!function_exists('curl_init')){die('Sorry cURL is not installed!');}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // Set URL to download
curl_setopt($ch, CURLOPT_REFERER, $referer); // Set a referer
curl_setopt($ch, CURLOPT_USERAGENT, $browserAgent); // User agent
curl_setopt($ch, CURLOPT_HEADER, 1); // include header?
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // print out the data?
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Timeout in seconds
$output = curl_exec($ch); // return output
curl_close($ch); // Close the cURL
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment