简体   繁体   English

PHP执行外部文件

[英]PHP Execute External File

I have a file located on my server and I want to remotely access that file from another server and execute source code of the file from another PHP file located on the another server. 我的服务器上有一个文件,我想从另一台服务器远程访问该文件,并从另一台服务器上的另一个PHP文件执行文件的源代码。

I have had a look at “File_get_contents” however this only obtains the content displayed by that PHP file, as can be seen below. 我看过“ File_get_contents”,但这只能获取该PHP文件显示的内容,如下所示。

So therefore is it possible for a PHP file from an external server to read the source code of the PHP file located on my server and execute the commands on the external server? 因此,是否有可能使外部服务器上的PHP文件读取位于我的服务器上的PHP文件的源代码并在外部服务器上执行命令?

You can use an extension other than .php for the source file, then use file_get_contents (or similar) to retrieve the contents. 您可以对源文件使用.php以外的扩展名,然后使用file_get_contents(或类似文件)来检索内容。

Not using the php extensions will prevent PHP from parsing it as code, and just send it over as text instead. 不使用php扩展名将阻止PHP将其解析为代码,而仅以文本形式发送。

However, that will also make the source readable to anyone who navigates to the file in a browser, as well as introducing a possible major vulnerability. 但是,这也将使任何在浏览器中导航到该文件的人都可以看到源,并且可能会引入一个重大漏洞。 You should look into why this is necessary and if it can be avoided somehow (perhaps calling the file on the other server with GET or POSTed parameters). 您应该研究为什么这样做是必要的,以及是否可以避免这种情况(也许在另一台服务器上使用GET或POSTed参数调用文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM