Medium
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Set blacklist
$substitutions = array(
'&&' => '',
';' => '',
);
// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
代码详解
1、isset--检测变量是否已声明并且其值不为 null,
若isset() 被赋值为 null
的变量,将返回 false,否则返回true。
例;
2、array_keys — 返回数组中部分的或所有的键名。
例:
3、str_replace — 子字符串替换
4、 stristr — 函数查找字符串在另一个字符串中第一次出现的位置。
5、php_uname — 返回运行 PHP 的系统的有关信息