PHP中包含返回空白或错误的网页的所有方法


All methods of including webpage returning blank or error in PHP

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

我试过file_get_contents()cURLfopen,它们在我的电脑上都很好用,但联机失败了。

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行

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

您也可以尝试:

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