看板 PHP 關於我們 聯絡資訊
※ 引述《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
zuo3:蝦密url_include 這麼危險 那我還是把他off起來 10/15 23:31
buganini:include('http://x.x.x.x/a.php');會是把a.php執行後的 10/15 23:32
buganini:結果include進來沒錯啊.... 10/15 23:32
zuo3:一個一個慢慢修正為../memu.php (天阿 有90個要改) 10/15 23:32
zuo3:感謝 buganini&ybite 大大 問題解決了 (問題解決原文刪除) 10/15 23:38
buganini:eval('?>'.file_get_contents($url).'<?php '); 10/15 23:40
buganini:可以用allow_url_fopen替代allow_url_include 10/15 23:41
buganini:不過一樣危險就是了.... 10/15 23:42