作者ybite (小犬)
看板PHP
标题Re: [请益] 有关include的写法?
时间Mon Oct 15 23:22:42 2007
※ 引述《zuo3 (完美的一天)》之铭言:
: 标题: [请益] 有关include的写法?
: 时间: Mon Oct 15 23:00:56 2007
:
: 这应该是非常简单的问题吧
: 但是我一直搞不定(因为完全不懂php)
: 问题是这样的
: 在http://***.***.**/content/section01/item01.php 的网页中
: 要include(http://***.***.**/content/menu.php)
: 但是网页显示是
: Warning: include() [function.include]: URL file-access is disabled in the
: server configuration in D:\WebRoot\content\section02\item03.php on line 2
: Warning: include(http://***.***.**/content/menu.php) [function.include]:
: failed to open stream: no suitable wrapper could be found in
: D:\WebRoot\content\section02\item03.php on line 2
这种错误很显然是因为allow_url_include没有打开(disabled in configuration)
: 但如果尝试 直接改为 include(menu.php) 并把menu.php 移至 section01资料夹中
:
: 便可以直接开启 但总觉得这样很笨 且原始的写法并非如此 也维护不易
我个人觉得这样子并不笨,反而是最理想的作法
除非你是另外一些档案"一定"得摆在另一个server里面
这样的情况下使用readfile来读内容或着AJAX都比直接include好...
直接include一个URL十分危险...
: 我知道这应该是很简单的问题 而且也是很蠢的问题 而且该自己好好爬文
: 但是.......我根本不懂php 真的很抱歉 请各位大大帮个忙 我会自d这种废文的
: ps1 这是用appserv 架站的
: ps2 这是承继既有的网站架构
: ps3 这是老板指派给我的鸟工作--把关闭半年左右的网站重新架起
: 推 buganini:不笨啊....倒是原本的写法怪怪的 10/15 23:08
: → buganini:而且注意你include url是php执行後的结果喔 10/15 23:08
并不是这样子,是可以include source code的...
http://tw2.php.net/include states:
Security warning
Remote file may be processed at the remote server (depending on the file
extension and the fact if the remote server runs PHP or not) but
it still has
to produce a valid PHP script because it will be processed at the local
server. If the file from the remote server should be processed there and
outputted only, readfile() is much better function to use. Otherwise, special
care should be taken to secure the remote script to produce a valid and
desired code.
因为allow_url_include所引起的相关安全性与入侵问题并不小
强烈建议不要打开这个功能,也不要做这麽危险的include...
: → buganini:你可以include('../menu.php')不用搬档案 10/15 23:09
: → buganini:不然就去把php.ini里面allow_url_include打开 10/15 23:09
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.248.110
1F:→ zuo3:虾密url_include 这麽危险 那我还是把他off起来 10/15 23:31
3F:→ buganini:结果include进来没错啊.... 10/15 23:32
4F:→ zuo3:一个一个慢慢修正为../memu.php (天阿 有90个要改) 10/15 23:32
5F:推 zuo3:感谢 buganini&ybite 大大 问题解决了 (问题解决原文删除) 10/15 23:38
6F:推 buganini:eval('?>'.file_get_contents($url).'<?php '); 10/15 23:40
7F:→ buganini:可以用allow_url_fopen替代allow_url_include 10/15 23:41
8F:→ buganini:不过一样危险就是了.... 10/15 23:42