最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
file_get_contents被屏蔽解决方法
时间:2022-06-24 23:35:21 编辑:袖梨 来源:一聚教程网
那么一般情况下,我们改不了服务器的 inc.php,只能自己写一套IO来代替上面的PHP函数了。
| 代码如下 | 复制代码 |
|
|
|
我们可以用下面的代码代替
| 代码如下 | 复制代码 |
|
//禁用file_get_contents的解决办法 |
|
curl是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP、FTP、TELNET等,它不会被服务器禁用,所以我们可以用来模拟file_get_contents一样打开一条URL。
利用function_exists函数来判断php是否支持一个函数可以轻松写出下面函数
| 代码如下 | 复制代码 |
|
function vita_get_url_content($url) { if(function_exists('file_get_contents')) { $file_contents = file_get_contents($url); } else { $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); } return $file_contents; } ?> |
|
相关文章
- 三角洲云游戏网页版极速畅玩-三角洲云游戏一键秒玩入口 11-02
- Windows 11 如何永久禁用会自动重启的 SearchHost.exe? 11-02
- 漫蛙manwa2链接入口-漫蛙manwa2网页直达入口 11-02
- jm漫画天堂-禁漫成人隐藏入口 11-02
- AO3镜像站合集-10个实测可用AO3入口网址速存 11-02
- pixiv网页版手机入口-pixiv手机网页登录入口 11-02