gpt4 book ai didi

php - 警告,由 php 文件后的尾随路径引起的 open_basedir 限制生效

转载 作者:可可西里 更新时间:2023-10-31 23:40:44 25 4
gpt4 key购买 nike

首先让我说我知道这个问题被问了很多。不过,没有什么能真正解决我的问题。

脚本小子正在通过点击类似

的 url 来寻找管理路径
mysite.com/index.php/admin/login

主文件正在拦截他们的请求并查看他们是否请求了真实文件。这在未配置 open_basedir 的服务器上被拒绝且没有警告,这是正确的行为。不幸的是,在我们确实使用 open_basedir 的服务器上,file_exists 函数会抛出警告。

我已将其缩小为一个简单的示例。

将其放入 index.php 并将路径更改为您的 php 文件所在的文件夹

<?php
ini_set('open_basedir', '/path/to/files');

var_dump(
ini_get('open_basedir'), // make sure the config took hold
file_exists(realpath('index.php').'/')
);

现在您会看到一个警告,例如

Warning: file_exists() [<a href='function.file-exists'>function.file-exists</a>]: open_basedir restriction in effect. File(/path/to/files/index.php/) is not within the allowed path(s): (/path/to/files) in /path/to/files/index.php on line

编辑:

需要注意的是,请求带有尾部斜杠的不存在的文件不会导致警告。

var_dump('/path/to/files/bogus.php/');

不会引起任何警告并返回 false,这符合预期。

为了澄清我的问题,为什么会抛出警告,我可以避免吗?

第二次编辑:

我正在运行 php 版本 5.3.3-7+squeeze17 我会尽快在较新的版本中试用

最佳答案

这个确切的行为被报告为 PHP 5.2.2 - 5.2.3 中的错误:

https://bugs.php.net/bug.php?id=41518

然后在 5.3.3.7 - 5.4.17 中报告存在。

https://bugs.php.net/bug.php?id=53041

结论是好像是个bug。

关于php - 警告,由 php 文件后的尾随路径引起的 open_basedir 限制生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22366160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com