0

私はPHPコーディングが初めてで、新しい単純なスクリプトを書いていますが、このコードを配置すると空白のページが表示されます。このコードの何が問題なのか教えてもらえますか?

<?php
if($_POST) {
$host = $_POST['host'];
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
if(!($con = ssh2_connect("127.0.0.1", "22")))
{
    echo "fail: unable to establish connection";
}
else
{
    if(!ssh2_auth_password($con, "root", "password"))
    {
        echo "fail: unable to authenticate ";
    }
    else
    {

        $stream = ssh2_exec($con, "".$host."");
            stream_set_blocking($stream, true);
        $item = "";
        while ($input = fread($stream,4096)) {
               $item .= $input;
        }
        echo $item;
    }
}

?>

私の悪い日本語でごめんなさい

4

3 に答える 3

0

OPの質問ではないかもしれませんが、タイトルには php sshpass ssh と記載さsshpasssshています

$ssh_host = "127.0.0.1";
$ssh_port = "22";
$ssh_user = "root";
$ssh_pass = "password";
$command = "uname -a";
$connection = "/usr/bin/sshpass -p $ssh_pass /usr/bin/ssh -p $ssh_port -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $ssh_user@$ssh_host";
$output = exec($connection." ".$command." 2>&1");
echo "Output: $output";
于 2016-11-30T01:49:41.597 に答える
0

PHPでssh2を動作させるために数日間働きました[wwwの専用サーバー管理パネル]が、出力に関する問題の解決策が見つかりませんでした。機能する唯一のこと (ただし、これは一部のスクリプトでのみ十分です) は、「exec」と「read」の間でしばらくスリープすることです。

$stream = ssh2_exec($connection->conn, 'pgrep screen');
stream_set_blocking($stream, true);
// sleep 0.5 sec, this trick won't work for commands that execution time is unpredictable
usleep(500000);
$line = '';
while($get = fgets($stream))
{
    $line .= $get;
}
echo $line;
于 2015-02-02T20:50:49.957 に答える