简体   繁体   English

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

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

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

To prevent users setting PHP config values in .htaccess files, do not give AllowOverride Options permissions on their virtual hosts. 要防止用户在.htaccess文件中设置PHP配置值,请不要在其虚拟主机上授予AllowOverride Options权限。

Alternatively, install PHP as CGI instead of as an Apache module, as the CGI version is unaffected by .htaccess files. 或者,将PHP安装为CGI而不是Apache模块,因为CGI版本不受.htaccess文件的影响。 However, since PHP 5.3.0, PHP CGI does parse per-directory php.ini files. 但是,从PHP 5.3.0开始,PHP CGI确实解析了每个目录的php.ini文件。 I am not aware of a method that turns this off. 我不知道一种方法可以解决这个问题。

EDIT: I've just seen this in the latest default 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

So if you put directives in your main php.ini under per-directory headings they cannot be overridden. 因此,如果您在主目录标题下的主php.ini中放置指令,则无法覆盖它们。 However, the downside is that you'll have to do this for every virtual host so it'll be a PITA in environments where there are many or where new ones are frequently added. 但是,缺点是您必须为每个虚拟主机执行此操作,因此它将在有许多或经常添加新的虚拟主机的环境中成为PITA。

EDIT AGAIN: 再次编辑:

Further reading has revealed this: 进一步阅读揭示了这一点:

; 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 =

So just uncomment that last line to disable per-user ini files. 因此,只需取消注释最后一行即可禁用每个用户的ini文件。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM