【问题标题】:Basic PHP form submitting PowerShell基本 PHP 表单提交 PowerShell
【发布时间】:2016-10-05 11:17:58
【问题描述】:

我正在尝试创建一个用于运行 PowerShell 脚本的基本表单。我环顾四周,Robin 使用 IIS 和 PHP 运行 PowerShell 脚本提供了一个很好的解决方案。 来源:http://theboywonder.co.uk/2012/07/29/executing-powershell-using-php-and-iis/ 我用他自己的代码进行了测试,但用我自己的 PS 脚本修改了路径变量,结果很好。

我现在正在尝试创建一个基本表单,它只有一个提交函数,onclick 将运行 PS 脚本并将结果返回到同一页面。

这是我从他的示例中提取的稍作修改的 PHP 代码。

<?php
// If there was no submit variable passed to the script (i.e. user has visited the page without clicking submit), display the form:
if(!isset($_POST["submit"]))
{
?>
<form name="testForm" id="testForm" action="pstest4.php" method="post">
   <input type="submit" name="submit" id="submit" value="Do stuff" />
</form>
<?php    
}
// Else if submit was pressed, check if all of the required variables have a value:
elseif((isset($_POST["submit"]))
{
// Get the variables submitted by POST in order to pass them to the PowerShell script:
// Path to the PowerShell script. Remember double backslashes:
$psScriptPath = "\\\\appswebfront\\Scripts\\mock.ps1";

// Execute the PowerShell script, passing the parameters:
$query = shell_exec("powershell -command $psScriptPath < NUL");
echo $query;    
}
?>

我运行它,我得到:

Parse error: syntax error, unexpected ';' in \\APPSWEBFRONT\INETPUB\wwwroot\pstest4.php on line 31

在我的预览中,第 31 行以 $psScriptPath 开头。

当然,如果我删除分号,它会直接转到下一个分号,直到显示unexpected $query' (T_VARIABLE)

我确定某处存在一些不正确的语法,但由于我是一个纯粹的 PHP 初学者,我不知道我哪里出错了。

归根结底,当提交按钮未被点击/发布时,我需要页面显示表单,点击后,它会运行 PS 脚本并将输出返回到同一页面。

请帮忙。

【问题讨论】:

    标签: php forms powershell submit


    【解决方案1】:

    这行括号太多了elseif((isset($_POST["submit"]))

    应该是elseif(isset($_POST["submit"]))

    尝试一下并告诉我们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多