^()[]{}$\, \x0A 和 \xFF。 ' 和 " "="" 字符都會被空格代替。="" !="" 和="" %="" 平臺上,所有這些字符以及="" windows="" 在="" 僅在不配對兒的時候被轉(zhuǎn)義。="">

escapeshellcmd

(PHP 4, PHP 5, PHP 7, PHP 8)

escapeshellcmdshell 元字符轉(zhuǎn)義

說明

escapeshellcmd(string $command): string

escapeshellcmd() 對字符串中可能會欺騙 shell 命令執(zhí)行任意命令的字符進行轉(zhuǎn)義。 此函數(shù)保證用戶輸入的數(shù)據(jù)在傳送到 exec()system() 函數(shù),或者 執(zhí)行操作符 之前進行轉(zhuǎn)義。

反斜線(\)會在以下字符之前插入: &#;`|*?~<>^()[]{}$\, \x0A\xFF。 '" 僅在不配對兒的時候被轉(zhuǎn)義。 在 Windows 平臺上,所有這些字符以及 %! 字符都會被空格代替。

參數(shù)

command

要轉(zhuǎn)義的命令。

返回值

轉(zhuǎn)義后的字符串。

范例

示例 #1 escapeshellcmd() example

<?php
// 我們故意允許任意數(shù)量的參數(shù)
$command './configure '.$_POST['configure_options'];

$escaped_command escapeshellcmd($command);
 
system($escaped_command);
?>

警告

escapeshellcmd() 應(yīng)被用在完整的命令字符串上。 即使如此,攻擊者還是可以傳入任意數(shù)量的參數(shù)。 請使用 escapeshellarg() 函數(shù) 對單個參數(shù)進行轉(zhuǎn)義。

更新日志

版本 說明
5.4.43, 5.5.27, 5.6.11 感嘆號會被空格所替換。

參見