Home > php教程 > php手册 > body text

php父级目录文件包函问题

WBOY
Release: 2016-06-06 19:48:16
Original
1272 people have browsed it

问题: php子目录不能包函父目录中的文件。 环境: 网站根目录:/var/www/html/ PHP版本: 5.3.3 Apache版本:2.2 好了,创建三个文件: // 文件路径:/var/www/html/a.php ? php echo "a.php"; // 文件路径:/var/www/html/test/b.php ? php include "../a.ph

问题:

  php子目录不能包函父目录中的文件。

环境:

网站根目录:/var/www/html/

PHP版本: 5.3.3

Apache版本:2.2

好了,创建三个文件:

<span>//</span><span>文件路径:/var/www/html/a.php</span>
<span>php
    </span><span>echo</span> "a.php";
Copy after login

 

<span>//</span><span>文件路径:/var/www/html/test/b.php</span>
<span>php
    </span><span>include</span> "../a.php"<span>;
    </span><span>echo</span> "b.php"<span>;
</span>?>
Copy after login

 

<span>//</span><span>文件路径:/var/www/html/c.php</span>
<span>php
    </span><span>include</span> "./a.php"<span>;
    </span><span>echo</span> "c.php"<span>;
</span>?>
Copy after login

主要来看b.php

我们期待的执行结果是,php父级目录文件包函问题

 

但是实际上呢:php父级目录文件包函问题

但是c.php文件中执行没有问题。

 

解决方案:

修改/etc/php.ini文件

在第380行的open_basedir属性。

在其后面添加网站根目录

open_basedir =.:/tmp/:/var/www/html/

open_basedir属性是做什么的呢?表示允许访问的目录,开启这个配置项,可以防止php木马跨站。

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!