提交 PowerShell 的基本 PHP 表单
Basic PHP form submitting PowerShell
我正在尝试为 运行ning PowerShell 脚本创建一个基本表单。我环顾四周,Robin 运行ning PowerShell 脚本使用 IIS 和 PHP 提供了一个很好的解决方案。
资料来源:http://theboywonder.co.uk/2012/07/29/executing-powershell-using-php-and-iis/
我 运行 用他自己的代码进行了测试,但用我自己的 PS 脚本修改了路径变量,结果很好。
我现在正在尝试创建一个基本表单,它只有一个提交功能,onclick 将 运行 PS 脚本和 return 结果返回到同一页面.
这是我从他的示例中提取的稍微修改过的 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 的初学者,我不知道我哪里出错了。
归根结底,当提交按钮不是 clicked/posted 时,我需要页面显示表单,点击后,它会 运行 PS脚本和 return 输出返回到同一页面。
请帮忙。
你这一行的括号太多elseif((isset($_POST["submit"]))
应该是elseif(isset($_POST["submit"]))
。
试试看,然后告诉我们。
我正在尝试为 运行ning PowerShell 脚本创建一个基本表单。我环顾四周,Robin 运行ning PowerShell 脚本使用 IIS 和 PHP 提供了一个很好的解决方案。 资料来源:http://theboywonder.co.uk/2012/07/29/executing-powershell-using-php-and-iis/ 我 运行 用他自己的代码进行了测试,但用我自己的 PS 脚本修改了路径变量,结果很好。
我现在正在尝试创建一个基本表单,它只有一个提交功能,onclick 将 运行 PS 脚本和 return 结果返回到同一页面.
这是我从他的示例中提取的稍微修改过的 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 的初学者,我不知道我哪里出错了。
归根结底,当提交按钮不是 clicked/posted 时,我需要页面显示表单,点击后,它会 运行 PS脚本和 return 输出返回到同一页面。
请帮忙。
你这一行的括号太多elseif((isset($_POST["submit"]))
应该是elseif(isset($_POST["submit"]))
。
试试看,然后告诉我们。