Created
October 10, 2018 04:22
-
-
Save selfhow/113563e4c1fd901d941b8b117a05a780 to your computer and use it in GitHub Desktop.
curl_get_content
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_get_content($url, $headers=0, $is_get=true, $follow_location=true, $referer="no-referrer-when-downgrade", $need_false_info=false, $postfields="", $proxyurl=null) { | |
$agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0'; | |
$curlsession = curl_init (); | |
curl_setopt ($curlsession, CURLOPT_URL, $url); | |
curl_setopt ($curlsession, CURLOPT_HEADER, $headers); | |
curl_setopt ($curlsession, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt ($curlsession, CURLOPT_POST, $is_get ? 0 : 1); | |
if ($is_get == false){ // post | |
curl_setopt ($curlsession, CURLOPT_POSTFIELDS, $postfields); | |
} | |
curl_setopt ($curlsession, CURLOPT_FOLLOWLOCATION, $follow_location ? true : false); | |
curl_setopt ($curlsession, CURLOPT_USERAGENT, $agent); | |
curl_setopt ($curlsession, CURLOPT_REFERER, $referer); | |
curl_setopt ($curlsession, CURLOPT_TIMEOUT, 60); | |
if ($proxyurl != null){ | |
curl_setopt ($curlsession, CURLOPT_PROXY, $proxyurl); | |
} | |
$buffer = curl_exec ($curlsession); | |
$cinfo = curl_getinfo($curlsession); | |
curl_close($curlsession); | |
if ($cinfo['http_code'] != 200) | |
{ | |
if ($need_false_info === false){ | |
return ""; | |
}else{ | |
return $cinfo; | |
} | |
//echo $cinfo['http_code'] . "<hr />"; | |
} | |
return $buffer; | |
} | |
function curl_get_contents_utf8($url) { | |
$content = curl_get_content($url); | |
return htmlentities(str_replace(' ', ' ', mb_convert_encoding($content, 'HTML-ENTITIES', mb_detect_encoding($content)))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment