Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
curl_get_content
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('&nbsp;', ' ', 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
You can’t perform that action at this time.