【问题标题】:file_get_contents/curl PHP Function Not Working For IP Addressfile_get_contents/curl PHP 函数不适用于 IP 地址
【发布时间】:2014-10-08 04:53:20
【问题描述】:

我的服务器包含一个位于http://XX.XX.XX.XX:7550/check.txt 的文件,其中仅写入了Online。现在我在我的共享主机上,我想在我的共享主机 php 文件中获取Online,因为我在我的共享主机 php 文件中使用以下代码。

<?php
var_export(ini_get('allow_url_fopen'));
$uri = 'http://XX.XX.XX.XX:7550/check.txt';
$result = file_get_contents($uri);
echo $result;
?> 

但我只得到'1' 而不是'1' Online。那你能回答我为什么输入我的服务器IP时不起作用吗?

注意:当我添加 http://www.google.com 而不是 http://XX.XX.XX.XX:7550/check.txt 时,我将获得整个 Google 页面。

重要提示:我可以通过代理直接在我的网络浏览器中打开http://XX.XX.XX.XX:7550/check.txt,这意味着我的服务器中没有防火墙阻止(Ubuntu Server 14.04 LTS) .

更新:

我也尝试了CURL,这也不适用于http://XX.XX.XX.XX:7550/check.txt,而是使用http://www.google.com

<?php
function curl_load($url){
    curl_setopt($ch=curl_init(), CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}
$url = "http://XX.XX.XX.XX:7550/check.txt";
echo curl_load($url);
?>

【问题讨论】:

    标签: php apache curl file-get-contents shared-hosting


    【解决方案1】:

    尝试使用 cUrl 代替 file_get_contents。

    【讨论】:

    猜你喜欢
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    相关资源
    最近更新 更多