Menu

#185 failed to open stream: HTTP request failed!

wont-fix
None
2022-12-21
2020-11-14
Si Anh Pham
No

When excuting these code:

require_once 'simple_html_dom.php';
$url = "https://www.globalfitness.com/";
$html = file_get_html($url);
var_dump($html);

there is warning:

Warning: file_get_contents(https://www.globalfitness.com/): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:\xampp\htdocs\Newfolder\simple_html_dom.php on line 82
bool(false)

Discussion

  • LogMANOriginal

    LogMANOriginal - 2022-04-01
    • status: open --> wont-fix
    • assigned_to: LogMANOriginal
     
  • LogMANOriginal

    LogMANOriginal - 2022-04-01

    This site uses Cloudflare to protect against web crawlers and bots. Error 403 indicates that access to the site was denied, which may or may not occur depending on Cloudflare. This is not a bug in simplehtmldom.

     
    • Coz

      Coz - 2022-12-21

      This is not a bug in simplehtmldom

      Yes it is.

      You're not setting a user agent in either the curl code or the stream_context code. Any properly configured server will reject the requests, which makes the project useless.

      You need to either add a generic user agent (recommend google bot) or provide a way for the user to pass in their own user agent to the function.

      See lines 72 and 111 of revised HtmlWeb.php file.

       

Log in to post a comment.

MongoDB Logo MongoDB