curl采集数据请求

function ff_file_get_contents($url, $post_data=[], $timeout=5, $referer=''){
if(function_exists('curl_init')){
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt ($ch, CURLOPT_REFERER, $referer);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    //post
    if($post_data){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }
    //https
    $http = parse_url($url);
    // var_dump($http);die;
    if($http['scheme'] == 'https'){
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    }
    $content = curl_exec($ch);
    curl_close($ch);
    // var_dump($content);die;
    if($content){
        return $content;
    }
}
$ctx = stream_context_create(array('http'=>array('timeout'=>$timeout)));
$content = @file_get_contents($url, 0, $ctx);
if($content){
    return $content;
}
return false;}

💫 评论卡

备案号:粤ICP备18155514号-2