-1
我想知道我怎麼可以得到PHP運行命令 這裏是我的代碼:
<?php
$msg = $_GET['msg'];
echo "$msg test";
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
if(!($con = ssh2_connect("ip", 22))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, "root", "password")) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...\n";
// execute a command
if (!($stream = ssh2_exec($con, 'wall echo $msg'))) {
echo "fail: unable to execute command\n";
} else {
// collect returning data from command
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
fclose($stream);
}
}
}
?>
所以,它不會牆我在味精=這樣說。 ..它只是寫空白,但當我回聲$味精(如我在代碼頂部)它寫入通常,你們知道哪裏是問題?我已經嘗試過「echo $ msg」和「echo $ msh」,但是同樣的事情......感謝和最誠摯的問候!
它的工作原理!非常感謝你^ _^ –
@McFilip用於安全使用''牆'。 escapeshellarg($ msg)' – Devon
謝謝德文:) –