file_get_html error on one site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mavera2
Forum Newbie
Posts: 8
Joined: Sat Sep 03, 2011 11:54 am

file_get_html error on one site

Post by mavera2 »

I'm using simple html dom parser.
I used it in my web site successfully.
But i changed my host company and i can't run my existing codes.
"file_get_html" works on some sites. doesn't work on some sites.
i couldn't understand the problem.

This one works:

Code: Select all

include_once ('simple_html_dom.php');
$html1 = file_get_html('http://www.yahoo.com');
echo $html1;

Although web site can be opened from my browser, This one doesn't work in php script:

Code: Select all

include_once ('simple_html_dom.php');
$html2 = file_get_html('http://www.eksisozluk.com');
echo $html1;
-----------------------------
The same problem occurs again when i use in object oriented way.

Works:

Code: Select all

$html1 = new simple_html_dom();
$address1='http://www.yahoo.com';
$html1->load_file($address1);
echo "$html1";
Doesn't work:

Code: Select all

$html2 = new simple_html_dom();
$address2='http://www.eksisozluk.com';
$html2->load_file($address2);
echo "$html2";

The error is:

Warning: file_get_contents(http://www.eksisozluk.com) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home/mysite/public_html/myfolder/simple_html_dom.php on line 850

Fatal error: Call to a member function innertext() on a non-object in /home/mysite/public_html/myfolder/simple_html_dom.php on line 1364
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Re: file_get_html error on one site

Post by ok »

Some web hosting companies block certain PHP functions. They might also block certain sites.

What hosting company do you use? Is it free hosting?

Try to contact the hosting company to check if the problem comes from their end.
mavera2
Forum Newbie
Posts: 8
Joined: Sat Sep 03, 2011 11:54 am

Re: file_get_html error on one site

Post by mavera2 »

The interesting point is,
when i used free hosting the code was working,
when i bought a hosting account from different company the code didn't work.

I send a ticket to company, waiting for reply.
mavera2
Forum Newbie
Posts: 8
Joined: Sat Sep 03, 2011 11:54 am

Re: file_get_html error on one site

Post by mavera2 »

Another interesting thing is this code also works:

Code: Select all

echo '<iframe id="id1" name="name1" class="iframe1" src="http://www.eksisozluk.com"></iframe>';
So didn't they block the site??
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Re: file_get_html error on one site

Post by ok »

If you use iframe, the user's is loading the external site, but if you use PHP, you are the one who is loading the external site.
mavera2
Forum Newbie
Posts: 8
Joined: Sat Sep 03, 2011 11:54 am

Re: file_get_html error on one site

Post by mavera2 »

ok wrote:If you use iframe, the user's is loading the external site, but if you use PHP, you are the one who is loading the external site.
dear ok,
while waiting for company's reply is there any other way/function call to check if they blocked it?
Post Reply