2012-04-29 63 views
0

我試圖運行託管在不同服務器上的php函數。下面是相關的代碼:php包含來自不同服務器的文件

在firstdomain.com/handler.php:

include 'http://www.seconddomain.com/functions.php'; 
$disp_keyword = doQuery(0, $keyword, null); 

而且在seconddomain.com/functions.php:

function doQuery($code, $arg1, $arg2) { 
    mail('[email protected]', 'doquery entered', 'test'); 
} 

我怎樣才能得到這個工作?

+3

您必須確保'allow_url_fopen'已啓用並且'allow_url_include'也是如此。同時使_absolutely_確定您知道您遠程包含的文件的內容,並且100%可信。 – 2012-04-29 02:21:54

+1

見http://www.php.net/manual/en/features.remote-files.php和http://www.php.net/manual/en/function.include.php – 2012-04-29 02:22:31

回答

1

第二臺服務器上的文件需要輸出PHP源代碼,而不只是運行它。當你包含一個遠程文件時,就像在你的瀏覽器中那樣,然後運行顯示的代碼。

因此,最簡單的方法是忽略<?php?>標籤。但請記住,這會讓您的源代碼對外界可見 - 特別是任何安全性丟失。

2

分配的服務器默認設置將停止這個作爲它的高度不安全,但有一個簡單的工作圍繞使用eval,就像不安全,如果你不100%信任源。

而不是使用

include 'http://www.seconddomain.com/functions.php'; 

使用:

<?php 
//get file content, save it .txt on the serving server so its not interpreted, 
// you could even encrypt it then base 64 it to keep it safe, then reverse the process 
$content = file_get_contents('http://www.seconddomain.com/file.txt'); 
eval ("?>$content"); 
?> 

,或者你可以抓住與FGC文件,保存它,然後只用一個正常的包括你選擇,你應該有什麼方法非常警惕文件的來源。

+0

很好的解決方法。 – 2012-04-29 04:53:31

相關問題