(PHP 4, PHP 5, PHP 7)
escapeshellcmd – shell 元字符转义
说明
escapeshellcmd
( string $command
) : string
escapeshellcmd() 对字符串中可能会欺骗
shell 命令执行任意命令的字符进行转义。
此函数保证用户输入的数据在传送到
[exec()](php7/function.exec) 或
[system()](php7/function.system) 函数,或者 [执行操作符](php7/language.operators.execution) 之前进行转义。
反斜线()会在以下字符之前插入:
`|*?~<>^()[]{}$, x0A
和 xFF。 ' 和 "
仅在不配对儿的时候被转义。
在 Windows 平台上,所有这些字符以及 % 和 ! 字符都会被空格代替。
参数
command
要转义的命令。
返回值
转义后的字符串。
范例
Example #1 escapeshellcmd() example
// 我们故意允许任意数量的参数
$command = './configure '.$_POST['configure_options'];
$escaped_command = escapeshellcmd($command);
system($escaped_command);
?>
Warning
escapeshellcmd() 应被用在完整的命令字符串上。
即使如此,攻击者还是可以传入任意数量的参数。
请使用 [escapeshellarg()](php7/function.escapeshellarg) 函数
对单个参数进行转义。
更新日志
版本
说明
5.4.43, 5.5.27, 5.6.11
感叹号会被空格所替换。
参见
[escapeshellarg()](php7/function.escapeshellarg) – 把字符串转码为可以在 shell 命令里使用的参数
[exec()](php7/function.exec) – 执行一个外部程序
[popen()](php7/function.popen) – 打开进程文件指针
[system()](php7/function.system) – 执行外部程序,并且显示输出
[执行运算符](php7/language.operators.execution)