如何在 Apache 服务器(和其他服务器)上检测 PHP 中对 .htaccess 的支持
出于安全原因,我需要检查客户端是否无法读取某个目录,即 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 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.
也许您可以将包含以下内容的 .htaccess 文件上传
到您的根目录,然后尝试访问有问题的目录,
如果它们不可访问,则它可以工作。
如果没有,您的房东应该能够轻松帮助您解决此问题
您所在的平台。
Maybe you can upload .htaccess file with such content:
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.
您可以通过
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.