无法将来自ssh执行的数据回显到PHP中的网页

时间:2016-02-25 19:13:33

标签: php ssh

我正在编写一个PHP脚本,我从用户那里获取输入,如服务器IP和另外一个输入。

在此可用之后,我对服务器进行ssh调用并执行一些命令。我想在网页上显示输出,但我得到错误为500(服务器错误)。

这是我的主要脚本,我从用户那里得到了输入:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Centos Health Checker</title>
<link rel="stylesheet" href="style.css" type="text/css" />

</head>
<body>
<center>
<div id="login-form">
<form method="post" action="redirectPage.php">
<table align="center" width="30%" border="0">
<tr>
<td><input type="text" name="IP" placeholder="System IP" required /></td>
</tr>
<tr>
<td><input type="text" name="Component" placeholder="Component" required /></td>
</tr>
<tr>
<td><button type="submit" name="submit">Check System</button></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>

这是我的目标网页:

<?php
function Connect()
{
        include('/home/as5714/php_data/Net/SSH2.php');
        $IP1 = $_POST['IP'];
        $Component1 = $_POST['Component'];

        $ssh = new Net_SSH2($IP1);
        if (!$ssh->login('centos', 'centos')) {
            exit('Login Failed');
        }

        echo $ssh->exec('pwd');
        echo $ssh->exec('ls -la');
}

if(isset($_POST['submit']))
{
        Connect();
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome - <?php echo $IP1; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
 <div id="left">
    <label>cleartuts</label>
    </div>
    <div id="right">
     <div id="content">
         Cennecting to ' <?php echo $IP1; ?>&nbsp; and Data is : <?php echo $data2; ?>&nbsp;<a href="homePage.php">Go Back</a>
        </div>
    </div>
</div>
</body>
</html>

使用上面的php代码时出现服务器错误(500)。

请注意,我正在使用linux服务器上的vim编辑器来处理脚本,并且没有任何可用的日志。另外,如果我只是运行程序直接在服务器上执行ssh连接和执行命令(php 123.php),我会在控制台上获得正确的数据。

请帮忙。

0 个答案:

没有答案