Skip to content

Instantly share code, notes, and snippets.

@stamat
Created April 18, 2013 02:31
Show Gist options
  • Save stamat/5409572 to your computer and use it in GitHub Desktop.
Save stamat/5409572 to your computer and use it in GitHub Desktop.
CURL request method
<?php
function request($url) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($c, CURLOPT_TIMEOUT, 5);
curl_setopt($c, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($c);
$responseInfo = curl_getinfo($c);
curl_close($c);
if (intval($responseInfo['http_code']) == 200) {
return $response;
} else {
return '';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment