mavera2 Posted September 3, 2011 Share Posted September 3, 2011 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: 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: 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: $html1 = new simple_html_dom(); $address1='http://www.yahoo.com'; $html1->load_file($address1); echo "$html1"; Doesn't work: $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 Quote Link to comment https://forums.phpfreaks.com/topic/246363-file_get_html-error-on-one-site/ Share on other sites More sharing options...
jcbones Posted September 3, 2011 Share Posted September 3, 2011 A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. You may need to check and make sure your host has fopen wrappers enabled. Quote Link to comment https://forums.phpfreaks.com/topic/246363-file_get_html-error-on-one-site/#findComment-1265135 Share on other sites More sharing options...
mavera2 Posted September 3, 2011 Author Share Posted September 3, 2011 A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. You may need to check and make sure your host has fopen wrappers enabled. As far as i found from google search i run this script. if( ini_get('allow_url_fopen') ) { echo "allo url fopen is OK"; } else { echo "allo url fopen is NOT OK"; } It gave the result OK. Quote Link to comment https://forums.phpfreaks.com/topic/246363-file_get_html-error-on-one-site/#findComment-1265143 Share on other sites More sharing options...
jcbones Posted September 3, 2011 Share Posted September 3, 2011 Sometimes the http:// protocol will fail because sites require that a user_agent exist. Since PHP defines this user_agent string as empty, then you would need to make sure it is populated. ; Define the User-Agent string. PHP's default setting for this is empty. ; http://php.net/user-agent ;user_agent="PHP" Quote Link to comment https://forums.phpfreaks.com/topic/246363-file_get_html-error-on-one-site/#findComment-1265152 Share on other sites More sharing options...
mavera2 Posted September 3, 2011 Author Share Posted September 3, 2011 Sometimes the http:// protocol will fail because sites require that a user_agent exist. Since PHP defines this user_agent string as empty, then you would need to make sure it is populated. ; Define the User-Agent string. PHP's default setting for this is empty. ; http://php.net/user-agent ;user_agent="PHP" dear jcbones, that really helped me much :) thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/246363-file_get_html-error-on-one-site/#findComment-1265159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.