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

时间:2011-10-20 20:15:49

标签: php security apache .htaccess

如何确保用户无法使用.htaccess或自定义php.ini覆盖设置 配置的任何提示我应该使用

1 个答案:

答案 0 :(得分:5)

要阻止用户在.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文件。 : - )