allow_url_fopen与安全以及PHP libcurl

类别:编程语言 点击:0 评论:0 推荐:

  allow_url_fopen=ON常常会给服务器和管理员带来麻烦,但是经常性(至少我这样认为)的我们需要远程读取某个东西,如果设置allow_url_fopen=OFF将其关闭,我们就没有办法远程读取。

  幸好我们有一个很好的PHP模块--curl。下面我就以一个例子说说我用curl远程读取的方法:

  第一,allow_url_fopen=ON的情况下:

<?php $str = file_get_contents("http://www.csdn.net/"); if ($str !== false) { // do something with the content echo $str; } ?>

  第二,allow_url_fopen = Off的情况下:

<?php $ch = curl_init("http://www.csdn.net/"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $str = curl_exec($ch); if ($str !== false) { // do something with the content echo $str; } curl_close($ch); ?>

备注:关于allow_url_fopen=ON带来的危害请看如何对PHP程序中的常见漏洞进行攻击(下)

本文地址:http://com.8s8s.com/it/it27989.htm