Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 file_get_contents不能获取带端口的网址

file_get_contents不能获取带端口的网址

发布时间:2018-11-20   编辑:www.jquerycn.cn
jquery中文网为您提供file,get,contents不能获取带端口的网址等资源,欢迎您收藏本站,我们将为您提供最新的file,get,contents不能获取带端口的网址资源
本文章来给各位同学介绍file_get_contents不能获取带端口的网址解决办法,有需要了解的同学可参考。


先们来了解file_get_contents() 函数,官方介绍说它是把整个文件读入一个字符串中。


例子

<?php
echo file_get_contents("test.txt");
?>

输出:

This is a test file with test text.

同样此函数还可以用于获取远程服务器上的内容


file_get_contents('http://www.111cn.net');

这样也是没有问题,但是如果我带了端口了就有问题了


例如:


file_get_contents('http://localhost:12345');


没有任何获取。

解决方法是 :关闭selinux

1 永久方法 – 需要重启服务器

修改/etc/selinux/config文件中设置SELINUX=disabled ,然后重启服务器。

2 临时方法 – 设置系统参数

使用命令setenforce 0

附:

setenforce 1 设置SELinux 成为enforcing模式
setenforce 0 设置SELinux 成为permissive模式

php的allow_url_fopen选项是关闭了

原因是我们php.ini中把php的allow_url_fopen选项是关闭了,我们只要把它打开即可。

如果你没有权限打开allow_url_fopen的话我们可使用curl函数的来替换,也是很方法的。

您可能感兴趣的文章:
file_get_contents不能获取带端口的网址
PHP fopen/file_get_contents与curl性能比较
php获取远程客户端真实ip地址
php获取网站ico
PHP通过IP获取地理位置的代码
连上wifi无线信号上不了网怎么办
php通过IP获取地理位置的实例参考
php获取ip地理信息几种方法
超简单的php获取ip地址信息的接口范例
php中file_get_contents 出现HTTP request failed! ...

[关闭]