使用PHP file_get_contents进行IP地址

时间:2017-02-16 16:02:02

标签: php ip file-get-contents

我正在使用file_get_contents从第二个网络服务器检索信息。我正在使用以下代码:

$json_url ="http://example.com/thisworks.html";
$json = file_get_contents($json_url);
$links = json_decode($json, TRUE);

但要连接到我的网络服务器,我正在使用带有端口的ip地址,但以下代码(带IPadress的file_get_contents)不起作用:

$json_url ="44.44.44:5000";
$json = file_get_contents($json_url);
$links = json_decode($json, TRUE);

(44.44.44当然是一个例子)

更新1:

我收到了错误:

[function.file-get-contents]: failed to open stream

更新2:

只是简单地添加http://无效

更新3:

http://44.44.44有效但http://44.44.44:5000没有(因为我使用的程序,我需要在网址中使用:5000端口)

有没有办法以这种方式使用file_get_contents?或者只能将其与http://或https://一起使用?

1 个答案:

答案 0 :(得分:0)

需要协议。

关于协议包装器http://php.net/manual/en/wrappers.php的php文档:

  

注意:用于描述包装器的URL语法仅支持scheme:// ...语法。方案:/和scheme:不支持语法。

UPD。您也可以注册自己的协议http://php.net/manual/ru/function.stream-wrapper-register.php

UPD 2 如果主机在添加协议后不起作用,请通过网络查看IP地址的可访问性

相关问题