Created
April 18, 2013 02:31
-
-
Save stamat/5409572 to your computer and use it in GitHub Desktop.
CURL request method
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
<?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