Skip to content

Instantly share code, notes, and snippets.

@mingcheng
Created November 27, 2012 02:48
Show Gist options
  • Save mingcheng/4152074 to your computer and use it in GitHub Desktop.
Save mingcheng/4152074 to your computer and use it in GitHub Desktop.
Gets the data from a URL
/* gets the data from a URL */
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11");
curl_setopt($ch, CURLOPT_REFERER, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment