您好,我使用php和ssh,并想执行一个图形程序,如gnome计算器。我该怎么做呢?这是我的代码:
<?php
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect("localhost", 22))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, "terminator", "root")) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...\n";
$get = $_GET['cmd'];
// execute a command
if (!($stream = ssh2_exec($con, $get ))) {
echo "fail: unable to execute command\n";
}
else {
// collect returning data from command
stream_set_blocking($stream, true);
$data = "";
while($line = fgets($stream)) {
echo nl2br($line);
}
fclose($stream);
}
}
}
?>
`我可以执行ls、-a或mkdir等命令,但我不能让应用程序执行图形界面(比如执行gnome计算器),我该怎么做呢?我这样使用我的代码:http://localhost/index.php?cmd=ls%20-a
只是玩玩而已!
发布于 2015-10-06 01:01:40
你希望它能从web浏览器内部弹出X-window应用吗?从超文本传输协议和X11应用程序的概念来看,这是不可能的。
发布于 2015-10-06 01:19:05
这是不可能的。在之前,PHP是在服务器端的上执行的,任何数据都会被传回客户机。如果您尝试执行任何应用程序,它将以您指定的用户(或web服务器的用户,如果未设置)的身份在服务器上运行,在服务器上解释的结果(如果它们被捕获),然后必须在网页上呈现给客户端。
要在客户机上运行外部程序,您需要使用在客户机上运行该语言的其他系统。这样的系统是否存在有待进一步讨论(换句话说,我不知道,所以我不打算为自己挖一个洞)
您需要考虑的明显问题是:如果客户端机器上没有安装和可用的应用程序,您该怎么办?
https://stackoverflow.com/questions/32951101
复制相似问题