我正在尝试更改密码。首先我必须以 root 身份登录,但我不知道确切的密码,所以我需要尝试 3 个不同的密码。我找到了如下解决方案,但我无法进入 if 语句。如果第一个密码不正确,我想尝试另一个。如果条件为空,我就离开了,因为我尝试了几件事,但都没有奏效。
if (!$ssh->login('ntsysadm', 'ABCD123')) {
echo" Login Failed to server". $iplist[$i];
}else{
echo "<br>";
echo "Connected to ".$iplist[$i];
echo "<br>";
$ssh->write("su - root\n");
$ssh->read('Password:');
$ssh->write("ABCD123\n");
if ( ) {
$ssh->write("su - root\n");
$ssh->read('Password:');
$ssh->write("ABC123\n");
if ( ) {
$ssh->write("su - root\n");
$ssh->read('Password:');
$ssh->write("ABC1234\n");} }
$ssh->read('#');
$ssh->write("passwd ".$_POST['username']."\n");
$ssh->read('password:');
$ssh->write($_POST['newpassword']."\n");
$ssh->read('password:');
$ssh->write($_POST['newpassword']."\n");
echo $logDetail = $ssh->read('successfully.');
echo "<br>";
mysql_query("INSERT INTO log VALUES ('','".$_SESSION['fullname']."','".$idlabuser."','".$serverId."','".$command."','".$datetime."','".$logDetail."') ");
}