【问题标题】:Execute Linux shell command using ajax and php使用 ajax 和 php 执行 Linux shell 命令
【发布时间】:2018-02-21 11:17:57
【问题描述】:

我有一个 HTML 页面,它有两个按钮,当我点击按钮时,我需要运行 2 个不同的 "sh" 命令,使用 PHP 和 Ajax 我该如何实现? p>

【问题讨论】:

  • 到目前为止你取得了什么成就?
  • 通过写代码..

标签: javascript php ajax linux shell


【解决方案1】:

你可以ajax request到php页面并使用exec

<?php
    // outputs the username that owns the running php/httpd process
    // (on a system with the "whoami" executable in the path)
    echo exec('whoami');
?>

【讨论】:

  • 如果他有权这样做!
  • 当然,用php执行Shell命令是最基本的??
【解决方案2】:
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>

来源:http://php.net/manual/de/function.shell-exec.php

【讨论】:

    最近更新 更多