手册如是说:
章 24. 安全模式
目录
被安全模式限制或屏蔽的函数
PHP 的安全模式是为了试图解决共享服务器(shared-server)安全问题而设立的。在结构上,试图在 PHP 层上解决这个问题是不合理的,但修改 WEB 服务器层和操作系统层显得非常不现实。因此许多人,特别是 ISP,目前使用安全模式。
表格 24-1. 控制安全模式的设置选项有:
设置选项 默认值
safe_mode Off
safe_mode_gid 0
safe_mode_include_dir ""
safe_mode_exec_dir 1
open_basedir ""
safe_mode_allowed_env_vars PHP_
safe_mode_protected_env_vars LD_LIBRARY_PATH
disable_functions ""
当 safe_mode 设置为 on,PHP 将检查当前脚本的拥有者是否和将被文件函数操作的文件的拥有者相匹配。例如: -rw-rw-r-- 1 rasmus rasmus 33 Jul 1 19:20 script.php
-rw-r--r-- 1 root root 1116 May 26 18:01 /etc/passwd
运行 script.php <?php
readfile('/etc/passwd');
?>
如果安全模式被激活,则将会导致以下错误: Warning: SAFE MODE Restriction in effect. The script whose uid is 500 is not
allowed to access /etc/passwd owned by uid 0 in /docroot/script.php on line 2
同时,或许会存在这样的环境,在该环境下,宽松的 GID 检查已经足够,但严格的 UID 检查反而是不适合的。您可以用 safe_mode_gid 选项来控制这种检查。如果设置为 On 则进行宽松的 GID 检查;设置为 Off(默认值)则进行 UID 检查。
除了 safe_mode 以外,如果您设置了 open_basedir 选项,则所有的文件操作将被限制在您指定的目录下。例如: <Directory /docroot>
php_admin_value open_basedir /docroot
</Directory>
如果您在设置了 open_basedir 选项后运行同样的 script.php,则其结果会是: Warning: open_basedir restriction in effect. File is in wrong directory in
/docroot/script.php on line 2
您也可以单独地屏蔽某些函数。请注意 disable_functions 选项不能在 php.ini 文件外部使用,也就是说您无法在 httpd.conf 文件的按不同虚拟主机或不同目录的方式来屏蔽函数。 如果我们将如下内容加入到 php.ini 文件: disable_functions readfile,system
则我们会得到如下的输出: Warning: readfile() has been disabled for security reasons i
章 24. 安全模式
目录
被安全模式限制或屏蔽的函数
PHP 的安全模式是为了试图解决共享服务器(shared-server)安全问题而设立的。在结构上,试图在 PHP 层上解决这个问题是不合理的,但修改 WEB 服务器层和操作系统层显得非常不现实。因此许多人,特别是 ISP,目前使用安全模式。
表格 24-1. 控制安全模式的设置选项有:
设置选项 默认值
safe_mode Off
safe_mode_gid 0
safe_mode_include_dir ""
safe_mode_exec_dir 1
open_basedir ""
safe_mode_allowed_env_vars PHP_
safe_mode_protected_env_vars LD_LIBRARY_PATH
disable_functions ""
当 safe_mode 设置为 on,PHP 将检查当前脚本的拥有者是否和将被文件函数操作的文件的拥有者相匹配。例如: -rw-rw-r-- 1 rasmus rasmus 33 Jul 1 19:20 script.php
-rw-r--r-- 1 root root 1116 May 26 18:01 /etc/passwd
运行 script.php <?php
readfile('/etc/passwd');
?>
如果安全模式被激活,则将会导致以下错误: Warning: SAFE MODE Restriction in effect. The script whose uid is 500 is not
allowed to access /etc/passwd owned by uid 0 in /docroot/script.php on line 2
同时,或许会存在这样的环境,在该环境下,宽松的 GID 检查已经足够,但严格的 UID 检查反而是不适合的。您可以用 safe_mode_gid 选项来控制这种检查。如果设置为 On 则进行宽松的 GID 检查;设置为 Off(默认值)则进行 UID 检查。
除了 safe_mode 以外,如果您设置了 open_basedir 选项,则所有的文件操作将被限制在您指定的目录下。例如: <Directory /docroot>
php_admin_value open_basedir /docroot
</Directory>
如果您在设置了 open_basedir 选项后运行同样的 script.php,则其结果会是: Warning: open_basedir restriction in effect. File is in wrong directory in
/docroot/script.php on line 2
您也可以单独地屏蔽某些函数。请注意 disable_functions 选项不能在 php.ini 文件外部使用,也就是说您无法在 httpd.conf 文件的按不同虚拟主机或不同目录的方式来屏蔽函数。 如果我们将如下内容加入到 php.ini 文件: disable_functions readfile,system
则我们会得到如下的输出: Warning: readfile() has been disabled for security reasons i
| 对此文章发表了评论 |
