开发者

How to detect support for .htaccess in PHP on Apache server (and other servers)

开发者 https://www.devze.com 2023-02-12 19:18 出处:网络
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

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 u开发者_JAVA技巧sing 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 ?


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.


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.


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号