duancai7002 2015-04-10 08:52
浏览 104
已采纳

如何使用PHP代码登录linux服务器?

I want to make a GUI for automation testing tool, currently that was in CLI and we need to convert it ig GUI, now the problem i am facing is that I have selected HTML,CSS,JS for front end and PHP for backend, so can any 1 of u suggest me how to login to the server, which is having some IP? or simply how to login to linux server using PHP code?

  • 写回答

5条回答 默认 最新

  • duanji8615 2015-04-10 09:09
    关注

    You can open a connection via SSH with the "Secure Shell2" PHP module.

    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');

    and then execute a command :

    // 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);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿