提交PowerShell的基本PHP表单

时间:2016-10-05 11:17:59

标签: php forms powershell submit

我正在尝试创建运行PowerShell脚本的基本表单。我环顾四周,罗宾使用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脚本并将输出返回到同一页面。 / p>

请帮忙。

1 个答案:

答案 0 :(得分:0)

此行elseif((isset($_POST["submit"]))

上有太多括号

应为elseif(isset($_POST["submit"]))

试试并告诉我们。

相关问题