【问题标题】:All methods of including webpage returning blank or error in PHPPHP中包括网页返回空白或错误​​的所有方法
【发布时间】:2015-11-22 01:13:44
【问题描述】:

我正在尝试包含网页的内容,它在 localhost 上运行良好,但是当我将文件上传到服务器时它不再运行

我试过file_get_contents()、cURL、fopen,它们在我的电脑上都可以正常工作,但在网上失败了。

我的主机设置了 PHP.ini 中的变量来阻止我获取其他页面的内容吗?

<?php


$url = 'http://www.example.com';

echo stream_get_contents( fopen($url, 'r') );

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);     

echo $output;


echo file_get_contents( $url );
?> 

错误:

警告:fopen(http://www.example.com):打开流失败:网络 在 /srv/disk12/1999559/www/techmex.co.nf/test.php 上无法访问 第 6 行

警告:stream_get_contents() 期望参数 1 是资源, /srv/disk12/1999559/www/techmex.co.nf/test.php 中给出的布尔值 第 6 行

警告:file_get_contents(http://www.example.com):打开失败 流:网络无法访问 /srv/disk12/1999559/www/techmex.co.nf/test.php 第 17 行

【问题讨论】:

    标签: php curl file-get-contents


    【解决方案1】:

    大多数网络服务器默认禁用此功能,但如果您有权更改 php.ini,则应设置“allow_url_fopen = On”。

    你也可以试试:

    <?php
        ini_set('allow_url_fopen', 1);
        echo file_get_contents('http://www.example.com');
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      相关资源
      最近更新 更多