如何防止使用.htaccess或自定义php.ini重写设置


How to prevent override the setting using .htaccess or custom php.ini

如何确保用户不能使用。htaccess或自定义php.ini覆盖设置关于配置的提示,我应该使用

为防止用户在。htaccess文件中设置PHP配置值,请不要在虚拟主机上赋予AllowOverride Options权限。

或者,将PHP安装为CGI而不是Apache模块,因为CGI版本不受.htaccess文件的影响。但是,从PHP 5.3.0开始,PHP CGI可以解析每个目录的PHP .ini文件。我不知道有什么方法可以关闭这个

编辑:我刚刚在最新的默认php.ini中看到了这个:

; Directives following the section heading [PATH=/www/mysite] only
; apply to PHP files in the /www/mysite directory.  Directives
; following the section heading [HOST=www.example.com] only apply to
; PHP files served from www.example.com.  Directives set in these
; special sections cannot be overridden by user-defined INI files or
; at runtime. Currently, [PATH=] and [HOST=] sections only work under
; CGI/FastCGI.
; http://php.net/ini.sections

所以如果你把指令放在主php.ini的目录标题下,它们就不能被覆盖。然而,缺点是您必须为每个虚拟主机执行此操作,因此在有许多虚拟主机或经常添加新主机的环境中,它将成为一个PITA。

编辑:

进一步的阅读揭示了这一点:

; Name for user-defined php.ini (.htaccess) files. Default is ".user.ini"
;user_ini.filename = ".user.ini"
; To disable this feature set this option to empty value
;user_ini.filename =

所以取消最后一行的注释来禁用每个用户的ini文件。: -)