0

I am trying to do the following

$url = "http://halo-video.com/drama/ha";
$data = file_get_contents($url);

echo $data;

it give me a blank page or a 500 internal error, I tried load the site with my computer, and its load fine.

user1777711
  • 1,604
  • 6
  • 22
  • 32

3 Answers3

1

EDIT:

Ok, this was bugging me so figured out a fix.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://kissanime.com/Anime/Karneval');
curl_setopt($ch, CURLOPT_USERAGENT, 'myuseragent'); 
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_REFERER, "http://www.test.com");
$html = curl_exec($ch);
curl_close($ch);
echo $html;

This code works and fixed the redirect errors I was getting. Happy content grabbing.

earl3s
  • 2,393
  • 1
  • 23
  • 24
1

although reason could be different but my code (similar to yours) works fine so just append these lines into yours at appropriate places,

$useragent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7";
                 curl_setopt($s,CURLOPT_AUTOREFERER, true);
                    curl_setopt($s,CURLOPT_FOLLOWLOCATION, true);
                    curl_setopt($s,CURLOPT_MAXREDIRS, 5);
                    curl_setopt($s,CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($s, CURLOPT_HEADER, true);
Shivanshu
  • 1,230
  • 1
  • 11
  • 17
  • The response should not be Object move to here, if you access using your computer, the response is different. – user1777711 Oct 26 '13 at 05:26
  • FMI please refer to http://stackoverflow.com/questions/8099919/using-curl-to-download-a-sites-html-source-but-getting-different-file-than-int – Shivanshu Oct 26 '13 at 14:57
0

Use file() instead of file_get_contents()

$url = "http://kissanime.com/Anime/Karneval";
$data = file($url);

echo htmlspecialchars($data);