Detect support for php_value / php_flag in .htaccess to suppress errors - PHP CGI mode - mod_php

ぐ巨炮叔叔 提交于 2019-12-10 23:33:32

问题


I use php_value and php_flag rules in .htaccess such as:

php_value upload_max_filesize 100M

But this causes an error when the server is running in CGI mode instead of Apache mode, and instead I have to use php.ini rules such as:

upload_max_filesize = 100M

My code libraries needs to work for either mode, without manual changes for each server.

It took me a while to find a solution to allow both methods to be in place, and as it was hard to find I thought I'd post my solution here.


回答1:


You can detect mod_php in .htaccess and ensure that these directives are only attempted when supported. In .htaccess:

<IfModule mod_php5.c>
   php_value upload_max_filesize 100M
   php_flag ...
</IfModule>

Note: Depending on your setup you might need to change mod_php5.c to mod_php4.c or mod_php.c.

In addition, you can manually stop the redundant php.ini file from being publicly accessible when in php mode using the following in .htaccess:

<Files ~ "\.ini">
   Order allow,deny
   Deny from all
</Files>

Hope this saves you some time!



来源:https://stackoverflow.com/questions/33998265/detect-support-for-php-value-php-flag-in-htaccess-to-suppress-errors-php-cg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!