javascript - 如何使用PHP代码登录Linux服务器?

标签 javascript php html linux login-page

我想为自动化测试工具制作一个GUI,目前是在CLI中,我们需要将其转换为GUI,现在我面临的问题是我选择了HTML,CSS,JS作为前端,PHP作为前端后端,那么你们中的任何一个人都可以建议我如何登录到有IP的服务器吗?或者只是如何使用 PHP 代码登录 Linux 服务器?

最佳答案

您可以使用“Secure Shell2”PHP 模块通过 SSH 打开连接。

https://php.net/manual/en/book.ssh2.php

// open a SSH connection (hostname = IP or network name of the remote computer)

$connection = ssh2_connect('hostname', 22);

// authenticate by login / password

ssh2_auth_password($connection, 'username', 'password');

然后执行命令:

// execute a shell command on the remote computer (eg. 'php -v' to know the PHP version)

$stream = ssh2_exec($connection, 'php -v');

// read the result from the remote computer to your local computer

stream_set_blocking($stream, true);

$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);

// print the result in your local computer

echo stream_get_contents($stream_out);

关于javascript - 如何使用PHP代码登录Linux服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29557196/

相关文章:

javascript - Twitter Bootstrap 轮播不自动启动

javascript - 将 JSON 放入表行中

JavaScript 代码签名

php - 在 JavaScript 中使用 smarty 数组

html - 如何在 HTML 中设置按钮的大小

html - http输出中的垃圾字节?

html - SVG 中的 MathJax

javascript - 传入表单数据没有给出响应

javascript - div限制字符的文本,添加 "Read more"链接,点击链接显示所有字符

php - 使用 PDO 获取一列