3

When I try to read the rss feeds of the kat.cr using php file_get_contents function, I get some unreadable text but when I open it up with my browser the feed is fine.
I have tried many other hosts but no chance in getting the correct data.
I even have tried setting the user-agent to diffrent browsers but still no change.
this is a simple code that I've tried:

$options  = array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1'));
$url = 'https://kat.cr/movies/?rss=1';
$data = file_get_contents($url, FILE_TEXT, stream_context_create($options));
echo $data;

I'm curious how their doing it and what I can do to overcome the problem.

A part of unreadable text:

‹ي]يrم6–‎?Oپي©™ت,à7{»‌âgw&يؤe;éN¹\S´HK\S¤–¤l+ے÷ِùِIِ”(إژzA5‌ةض؛غ%K4ـ{qtqy½ùوa^ »¬nٍھ|ûٹSِ eه¤Jَrِْصڈ1q^}sü§7uسlدزؤYً¾²yفVu‌•يغWGG·Iس&m>،“j~$ےzؤ(?zï‍ج’²جٹم?!ّ÷¦حغ";‏گ´Yس¢ï³{tر5ز ³َsgYٹْ.ں@

Actually everytime I open up the link there is some different unreadable text.

5
  • What kind of unreadable text is it ? Can you paste the first few lines ? It may be an encoding issue
    – Mat
    Commented Feb 12, 2016 at 16:51
  • @Mat added it in my question
    – Mortie
    Commented Feb 12, 2016 at 16:56
  • the url you are targeting is ssl - perhaps supply ssl options in the $context arg Commented Feb 12, 2016 at 17:02
  • @RamRaider I have even tried many other sites that use similar php functions to unblock other sites and all of them retrun those unreadable texts... you can just try these sites or any other: unblocksite.org unblockwebsite.net
    – Mortie
    Commented Feb 12, 2016 at 17:11
  • the contents appear to be gzipped - parse though the appropriate gzip unzipper? Commented Feb 12, 2016 at 17:33

1 Answer 1

6

As I mentioned in the comment - the contents returned are gzip encoded so you need to un-gzip the data. Depending upon your version of php you may or may not have gzdecode installed, I don't but the function here does the trick.

if( !function_exists('gzdecode') ){
    function gzdecode( $data ){ 
        $g=tempnam('/tmp','ff'); 
        @file_put_contents( $g, $data );
        ob_start();
        readgzfile($g);
        $d=ob_get_clean();
        unlink($g);
        return $d;
    }   
}
$data=gzdecode( file_get_contents( $url ) );
echo $data;     
1
  • Wow that works great. so... does all browsers detect and decode gzip data automatically? is that some kind of standard?
    – Mortie
    Commented Feb 12, 2016 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.