安全模式
在线手册:中文 英文
PHP手册

被安全模式限制或屏蔽的函数

以下安全模式列表可能不完整或不正确。

安全模式限制函数
函数名 限制
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() 当 PHP 运行在 安全模式 时,不能使用此函数。
backtick operator 当 PHP 运行在 安全模式 时,不能使用此函数。
shell_exec()(在功能上和 backticks 函数相同) 当 PHP 运行在 安全模式 时,不能使用此函数。
exec() 只能在 safe_mode_exec_dir 设置的目录下进行执行操作。基于某些原因,目前不能在可执行对象的路径中使用 ..escapeshellcmd() 将被作用于此函数的参数上。
system() 只能在 safe_mode_exec_dir 设置的目录下进行执行操作。基于某些原因,目前不能在可执行对象的路径中使用 ..escapeshellcmd() 将被作用于此函数的参数上。
passthru() 只能在 safe_mode_exec_dir 设置的目录下进行执行操作。基于某些原因,目前不能在可执行对象的路径中使用 ..escapeshellcmd() 将被作用于此函数的参数上。
popen() 只能在 safe_mode_exec_dir 设置的目录下进行执行操作。基于某些原因,目前不能在可执行对象的路径中使用 ..escapeshellcmd() 将被作用于此函数的参数上。
fopen() 检查被操作的目录是否与被执行的脚本有相同的 UID(所有者)。
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)
apache_request_headers() 在安全模式下,以“authorization”(区分大小写)开头的标头将不会被返回。
header() 在安全模式下,如果设置了 WWW-Authenticate,当前脚本的 uid 将被添加到该标头的 realm 部分。
PHP_AUTH 变量 在安全模式下,变量 PHP_AUTH_USERPHP_AUTH_PWPHP_AUTH_TYPE$_SERVER 中不可用。但无论如何,您仍然可以使用 REMOTE_USER 来获取用户名称(USER)。(注意:仅 PHP 4.3.0 以后有效)
highlight_file(), show_source() 检查被操作的文件或目录是否与被执行的脚本有相同的 UID(所有者)。 检查被操作的目录是否与被执行的脚本有相同的 UID(所有者)。 (注意,仅在 4.2.1 版本后有效)
parse_ini_file() 检查被操作的文件或目录是否与被执行的脚本有相同的 UID(所有者)。 检查被操作的目录是否与被执行的脚本有相同的 UID(所有者)。 (注意,仅在 4.2.1 版本后有效)
set_time_limit() 安全模式下不起作用。
max_execution_time 安全模式下不起作用。
mail() 在安全模式下,第五个参数被屏蔽。(注意,仅自 PHP 4.2.3 起受影响)
任何使用 php4/main/fopen_wrappers.c 的函数 ??


安全模式
在线手册:中文 英文
PHP手册
PHP手册 - N: 被安全模式限制或屏蔽的函数

用户评论:

Stephen Dewey (13-Jul-2009 08:39)

curl_setopt() will not allow you to activate CURLOPT_FOLLOWLOCATION when in safe mode.

tschmieder at bitworks dot de (22-Sep-2007 02:04)

refers to the previuos posting of

bananarama
15-May-2006 10:11

"all file-handling and -management functions are restricted, just in case someones wondering why they're not listed here.
a script can run these functions on files without errors, if the files were created (are owned) by the same UID, the script was created (is owned) by."

.... or if the directory, in which the file is located, has the same UID as the script, which tries to use a file in that directory...

bananarama (15-May-2006 09:11)

all file-handling and -management functions are restricted, just in case someones wondering why they're not listed here.
a script can run these functions on files without errors, if the files were created (are owned) by the same UID, the script was created (is owned) by.

example:
you upload a script, it is owned by UID 720. you upload a picture, it is owned by UID 720. the script creates a thumbnail of the picture. the thumb is owned by UID 30 (the server/apache). this makes it impossible (?) to run a gallery script, which checks for newly uploaded pictures in order to create and display thumbs of them if you want to check, if a thumbnail already exists. the script would be owned by UID 720, the thumb by UID 30.
you could upload a script which creates a file (e.g. from a text file) with .php ending. this script would be owned by UID 30 and could access the thumbs, but it couldnt read the upload pictures.

<?
  $data = fread(fopen("test.txt", "r"), filesize("test.txt"));
  
  $file = "test.php";  
  if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; } 
  if (!fwrite($file_handle, $data)) { echo "Cannot write to file"; }   
  fclose($file_handle);
 
  chmod("test.php", 0777);
?>

zauker (21-Mar-2006 10:57)

The SAFE_MODE handling of glob() needs a checkup for security reasons.

In short - always with SAFE_MODE on:

1) glob() can still fetch all filenames in a directory not owned by the
same UID as the user, if just the first file in the directory (or more
specific, the glob-pattern) happens to be owned by the same user as the
PHP-script.

2a) No warning is raised if glob is used on another owner's directory
and there is no match.

2b) In those cases where SAFE_MODE correctly prohibits glob() from
fetching a list of files, the warning still discloses the first
filename.

Solution: glob() in SAFE_MODE should be restricted in the same way as
opendir() is

see the link http://bugs.php.net/bug.php?id=28932

Jan (23-Oct-2005 10:46)

It seems that glob and file_exists functions are also restricted in safe-mode.