2012-04-29 50 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

相关问题