如何在 Apache 服务器(和其他服务器)上检测 PHP 中对 .htaccess 的支持

发布于 2024-10-18 10:13:55 字数 305 浏览 9 评论 0原文

出于安全原因,我需要检查客户端是否无法读取某个目录,即 Apache 服务器支持 .htaccess (没有 AllowOverride None code> 在 apache 配置文件中)。这非常重要,因为我最近发现很多产品和框架都没有检查这一点(包括 Zend 和 Symphony)。有没有办法仅使用 PHP 来检查这一点?

顺便说一句,如果我错了,请纠正我,但似乎其他服务器(nginx 或 lighttpd)不支持 .htaccess。在这些情况下,如何检查客户端是否无法读取我的目录?

For security reasons, I need to check if a directory is not readable by a client, i.e. that the Apache server supports the .htaccess (no AllowOverride None in the apache configuration files). This is very important as I have recently discovered that a LOT of products and framework are not checking this (including Zend and Symphony). Is there a way to check this using only PHP ?

BTW, correct me if I am wrong but it seems that other servers (nginx or lighttpd) do not support .htaccess. In these cases, how can I check that my directory is not readable by a client ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

望她远 2024-10-25 10:13:55

您可以在 htaccess 中使用 SetEnvIf 来设置变量,然后从 PHP 内部访问它。这将告诉您 htaccess 是否正在使用(并且 SetEnvIf 模块是否正在运行)。但它不会告诉您更多信息 - 例如,它不会告诉您 mod_rewrite 是否可用。要了解哪些模块正在运行,您可以通过编程方式检查 phpinfo 的输出。

You could use SetEnvIf in htaccess to set a variable, and then access it from within PHP. That will tell you if htaccess is being used (and the SetEnvIf module is running). But it won't tell you much more - it won't tell you if mod_rewrite is available, for example. To tell what modules are running, you could check the output of phpinfo programatically.

む无字情书 2024-10-25 10:13:55

也许您可以将包含以下内容的 .htaccess 文件上传

Options -Indexes

到您的根目录,然后尝试访问有问题的目录,
如果它们不可访问,则它可以工作。

如果没有,您的房东应该能够轻松帮助您解决此问题
您所在的平台。

Maybe you can upload .htaccess file with such content:

Options -Indexes

to your root, and then try to access directories in question,
if they are not accessible, it works.

If not, your host should be able to help you easily with this whatever
platform you're on.

云柯 2024-10-25 10:13:55

您可以通过is_read(".htaccess")检查文件。

print_r(apache_get_modules()) 将显示加载的 Apache 模块。

You can check files by is_readable(".htaccess").

print_r(apache_get_modules()) will show you the loaded Apache modules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文