簡體   English   中英

PHP包含來自不同服務器的文件

[英]php include file from different server

我正在嘗試運行在其他服務器上托管的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( 'myemail@aol.com', 'doquery entered', 'test' );
}

我該如何工作?

分配服務器的默認設置將阻止此操作,因為它非常不安全,但是如果您不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抓取文件,進行保存,然后僅使用常規包含,那么您選擇的任何方法都應該對文件的來源保持警惕。

第二台服務器上的文件需要輸出PHP源代碼,而不僅僅是運行它。 當您包含一個遠程文件時,就像在瀏覽器中進入該文件一樣,但是隨后顯示的代碼將運行。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM