Last active
August 29, 2015 14:17
-
-
Save BeFiveINFO/26118f5ea85cea6a37e3 to your computer and use it in GitHub Desktop.
Pass URL and it returns html by curl
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 | |
/** | |
* This curl function might be useful when get_file_contents() cannot be used for any reasons. | |
* E.g. when you need to pass user agent etc. | |
* | |
* Todo: return array with response code & the content | |
*/ | |
function get_curl_output_by_url ( $_curl_url ) { | |
$ch = curl_init(); | |
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; | |
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); | |
curl_setopt($ch, CURLOPT_URL, $_curl_url); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$ch_data = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
if($http_code!=200) $ch_data = FALSE; | |
return $ch_data; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment