php中的安全模式是指的什么?
章 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 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 选项,则所有的文件操作将被限制在您指定的目录下。例如:
php_admin_value open_basedir /docroot
如果您在设置了 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 in
/docroot/script.php on line 2
被安全模式限制或屏蔽的函数
以下安全模式列表可能不完整或不正确。
表格 24-2. 安全模式限制函数
函数名 限制
dbmopen() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
dbase_open() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
filepro() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
filepro_rowcount() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
filepro_retrieve() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
ifx_*() sql_safe_mode 限制, (!= safe mode)
ingres_*() sql_safe_mode 限制, (!= safe mode)
mysql_*() sql_safe_mode 限制, (!= safe mode)
pg_loimport() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
posix_mkfifo() 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。
putenv() 遵循 ini 设置的 safe_mode_protected_env_vars 和 safe_mode_allowed_env_vars 选项。请参考 putenv() 函数的有关文档。
move_uploaded_file() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
chdir() 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。
dl() 该函数在安全模式中已被屏蔽。
backtick operator 该函数在安全模式中已被屏蔽。
shell_exec()(在功能上和 backticks 函数相同) 该函数在安全模式中已被屏蔽。
exec() 您只能在 safe_mode_exec_dir 设置的目录下进行执行操作。基于某些原因,目前不能在可执行对象的路径中使用 ..。
system() 您只能在 safe_mode_exec_dir 设置的目录下进行执行操作。基于某些原因,目前不能在可执行对象的路径中使用 ..。
passthru() 您只能在 safe_mode_exec_dir 设置的目录下进行执行操作。基于某些原因,目前不能在可执行对象的路径中使用 ..。
popen() 您只能在 safe_mode_exec_dir 设置的目录下进行执行操作。基于某些原因,目前不能在可执行对象的路径中使用 ..。
mkdir() 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。
rmdir() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
rename() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。
unlink() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。
copy() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。 (on source and target)
chgrp() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
chown() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。
chmod() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。 另外,您不能设置 SUID、SGID 和 sticky bits
touch() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。
symlink() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。 (注意:仅测试 target)
link() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。 (注意:仅测试 target)
getallheaders() 在安全模式下,以“authorization”(区分大小写)开头的头信息将不会被返回。警告:getallheaders() 无法在 aol-server 下实现!
header() 在安全模式下,如果您设置了 WWW-Authenticate,当前脚本的 uid 将被添加到该头信息的 realm 部分。
highlight_file(), show_source() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。 (注意,仅在 4.2.1 版本后有效)
parse_ini_file() 将检查您将要操作的文件/目录与正在执行的脚本是否有相同的 UID。 将检查您将要操作的目录和正在执行的脚本是否有相同的 UID。 (注意,仅在 4.2.1 版本后有效)
任何使用 php4/main/fopen_wrappers.c 的函数 ??

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
