0

我有一个返回网页链接的 PHP 脚本。我收到 500 个内部错误,这就是我的服务器日志所说的。我让我的朋友在他的服务器上尝试相同的代码,它似乎运行正确。有人可以帮我调试我的问题吗?警告说有关包装器的某些内容已禁用。我检查了第 1081 行,但没有看到allow_url_fopen

PHP 警告:file_get_contents(): http:// wrapper 在服务器配置中被 /hermes/bosweb/web066/b669/ipg.streamversetv/simple_html_dom.php 中的 allow_url_fopen=0 禁用,第 1081 行

PHP 警告:file_get_contents(http://www.dota2lounge.com/):无法打开流:在第 1081 行的 /hermes/bosweb/web066/b669/ipg.streamversetv/simple_html_dom.php 中找不到合适的包装器

PHP 致命错误:在 /hermes/bosweb/web066/b669/ipg.streamversetv/sim 中的非对象上调用成员函数 find()

<?php
 include_once('simple_html_dom.php');
 $target_url = 'http://www.dota2lounge.com/';
 $html = new simple_html_dom();
 $html->load_file($target_url);
  foreach($html->find(a) as $link){
    echo $link->href.'<br />';
  }
?>
4

2 回答 2

6
  1. 下载最新的 simple_html_dom.php:下载链接

  2. 在您喜欢的编辑器中打开 simple_html_dom.php 并将此代码添加到第一行(可以在之后添加<?php):

    function file_get_contents_curl($url) {
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);     
    
        $data = curl_exec($ch);
        curl_close($ch);
    
        return $data; }
    
  3. 查找以我开头的function file_get_html($url.....行是第 71 行,但您也可以在编辑器中使用搜索。(搜索 file_get_html)

  4. 编辑这一行(函数 file_get_html 之后的以下几行):

    $contents = file_get_contents($url, $use_include_path, $context, $offset);

    对此:

    $contents = file_get_contents_curl($url);

  5. 使用 file_get_html 而不是 load_file,它会为您工作,无需编辑 php.ini

于 2013-12-20T14:04:47.310 回答
1

您需要将allow_url_fopenphp 设置为 1 以允许fopen()与 url 一起使用。

参考:PHP:运行时配置

编辑:
还追踪了另一件事,您是否尝试过以这种方式加载?

<?php
    include_once('simple_html_dom.php');

    $html = file_get_html('http://www.dota2lounge.com/');

    foreach($html->find('a') as $link)
    {
        echo $link->href.'<br />';
    }
?>
于 2013-09-27T16:52:41.583 回答