gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:23:20 24 4
gpt4 key购买 nike

如何确保用户无法使用 .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 文件。 :-)

关于php - 如何防止使用 .htaccess 或自定义 php.ini 覆盖设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7841709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com