user13746 user13746 - 6 months ago 39
PHP Question

file_get_contents() doesn't work on concrete website

I'm trying to get HTML content from website www.pornhub.com (don't ask why :D) but classic

file_get_contents('http://www.pornhub.com');


doesn't work. I have also tried

$Url = 'https://www.pornhub.com/categories';

if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;


but it doesn't work either.

Does anyone know what I'm doing wrong?

thx for any help.

Answer

Kindly try this one:

$Url = 'https://www.pornhub.com/categories';

if (!function_exists('curl_init')){
    die('CURL is not installed!');
}
$ch = curl_init($Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // add this one, it seems to spawn redirect 301 header
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); // spoof
$output = curl_exec($ch);
curl_close($ch);

echo $output; // use echo to show contents