Created
January 20, 2015 02:07
-
-
Save sagive/5938ab5561c1a54606b3 to your computer and use it in GitHub Desktop.
Simple Curl Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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