Как использовать CURL вместо file_get_contents?

Я использую функцию file_get_contents для получения и отображения внешних ссылок на моей конкретной странице.

В моем локальном файле все в порядке, но мой сервер не поддерживает функцию file_get_contents , поэтому я попытался использовать cURL с приведенным ниже кодом:

 function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } echo file_get_contents_curl('http://google.com'); 

Но он возвращает пустую страницу. Что не так?

попробуй это:

 function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); $data = curl_exec($ch); curl_close($ch); return $data; } 

Это должно работать

 function curl_load($url){ curl_setopt($ch=curl_init(), CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); return $response; } $url = "http://www.google.com"; echo curl_load($url); 

// Вы можете попробовать это. Он должен работать нормально.

 function curl_tt($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $data = curl_exec($ch); curl_close($ch); return $data; } echo curl_tt("https://google.com");