I am trying to open a webpage and get it's contents. On the browser, it works fine. However, through PHP, I'm unable to get webpage contents. In fact, I'm not able to hit the URL either. I feel anything apart from a header is not able to discover the webpage. With other URLs, it works fine. Please suggest me a method to able to get the contents of this webpage.
Code: Select all
URL : https://kat.cr/usearch/life%20of%20pi/1. fopen
Code: Select all
$url = "https://kat.cr/usearch/life%20of%20pi/";
$handle = fopen($url, "r");Code: Select all
/* gets the data from a URL */
function get_data($url) {
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = "https://kat.cr/usearch/life%20of%20pi/";
$returned_content = get_data($url);
echo $returned_content;
}Code: Select all
$url = "compress.zlib://https://kat.cr/usearch/life%20of%20pi/";