Hello
when read the site content of http://www.google.com by using fopen it works fine
<?php
$fh = fopen("http://www.google.com/", "r");
while(!feof($fh))
{
$output = htmlspecialchars(fgets($fh, 1024));
echo ("$output<br />");
}
fclose($fh);
?>
But
when read the site content of http://www.youtube.com, it fails; gives error
why is that!
How to read the youtube.com source by using fopen (Or any other method)
<?php
$fh = fopen("http://www.youtube.com/", "r");
while(!feof($fh))
{
$output = htmlspecialchars(fgets($fh, 1024));
echo ("$output<br />");
}
fclose($fh);
?>
Thanks
Need help!
Read webpage source from fopen
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Read webpage source from fopen
They are likely blocking your request because your user agent is that of your servers, and not the browser.
You can emulate the user agent of the request by using cURL.
However, this is probably against their terms of use.
You can emulate the user agent of the request by using cURL.
Code: Select all
$url = 'http://some_page_you_want_to_visit.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //retrive output and do not display it
$content = curl_exec($ch);
Re: Read webpage source from fopen
Hello,
how to display the source then!
i hv tried like;
echo $content;
but gives nothing!
how to display the source then!
i hv tried like;
echo $content;
but gives nothing!
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Read webpage source from fopen
Do you have cURL lib installed? You can check using phpinfo().
Also, have to tried a different website?
More info please.
Also, have to tried a different website?
More info please.