
时间:2015-06-28 00:00 来源:IT猫扑网|http://www.itmop.com/ 作者:网管联盟 我要评论(0)
在使用php的curl获取远程文件,代码如下:
<? $ghurl = isset($_GET['id']) ? $_GET['id']:'http://www.itmop.com/'; // php 获取 function getContents($url){ $header = array(&Referer: http://www.itmop.com/&); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_HTTPHEADER,$header); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); //是否抓取跳转后的页面 ob_start(); curl_exec($ch); $contents = ob_get_contents(); ob_end_clean(); curl_close($ch); return $contents; } $contents = getContents($ghurl); echo $contents; ?> |
一般来说在win2003+iis下如,把php_curl.dll配置好就没问题了。
但笔者在 linux+apahe2.0+php5.2.12+directadmin,(一般国外主机商都是用这配置)如果获取的网址有301/302跳转,会报错:
| curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in *** |
关于这个问题,google,百度一下,都是在大篇长长的english,不精通linux的还真头痛。
解决办法其实很简单:登陆你的 directadmin
找到 ->>&PHP SafeMode Configuration& -->>看下图
把默认的 Default Safe 和 Default Open BaseDir 都 OFF,问题就解决了。
关键词标签:php curl,301,302转向
相关阅读 2021年最好用的10款php开发工具推荐 plsql developer怎么连接数据库-plsql developer连接数据库方法 php利用淘宝IP库获取用户ip地理位置 在 PHP 中使用命令行工具 php出现Cannot modify header information问题的解决方法大全 详解ucenter原理及第三方应用程序整合思路、方法
热门文章
2021年最好用的10款php开发工具推荐
plsql developer怎么连接数据库-plsql developer连接数据库方法
在 PHP 中使用命令行工具
php应用程序安全防范技术研究
关于php curl获取301或302转向的网址问题
人气排行 详解ucenter原理及第三方应用程序整合思路、方法 plsql developer怎么连接数据库-plsql developer连接数据库方法 PHP中防止SQL注入攻击 PHP会话Session的具体使用方法解析 PHP运行出现Notice : Use of undefined constant 的解决办法 PHP如何清空mySQL数据库 CakePHP程序员必须知道的21条技巧 PHP采集图片实例(PHP采集) 完美解决failed to open stream: HTTP request failed! <? phpinfo() ?>无法执行的解决办法 2021年最好用的10款php开发工具推荐 用header或meta实现PHP页面编码的区别
查看所有0条评论>>