【问题标题】:How to prevent override the setting using .htaccess or custom php.ini如何防止使用 .htaccess 或自定义 php.ini 覆盖设置
【发布时间】:2011-12-12 02:32:04
【问题描述】:

如何确保用户不能使用 .htaccess 或自定义 php.ini 覆盖设置 我应该使用的任何配置技巧

【问题讨论】:

  • 什么设置? PHP.ini 文件中的设置不能在 .htaccess 中被覆盖,但可以很容易地在任何 PHP 文件中被覆盖。
  • 如果我在我的主 php.ini 中设置 register_globals = Off 一些用户可以在他们的帐户中创建一个自定义 php.ini 并获得这个值,我需要强制系统忽略所有这些自定义设置和读取已经关闭的 php.ini“主文件”值
  • @animuson - 很多设置确实可以在 .htaccess 中使用php_value 指令(和其他指令)覆盖。见the PHP manual
  • @daiscog 我需要防止这种情况被覆盖 :) 有什么提示可以保护我的盒子吗?
  • @marco:某些指令根本无法在脚本中工作。 register_globals 就是其中之一。在脚本中到达 ini_set() 时,PHP 的设置/初始化阶段已经结束。

标签: php security apache .htaccess


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-28
    • 2012-12-06
    • 1970-01-01
    • 2010-12-16
    • 2013-12-27
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多