【发布时间】:2016-11-30 09:32:29
【问题描述】:
我正在尝试进入加载页面,然后执行 powershell 脚本。但不幸的是,我无法让它发挥作用。当我转到该页面时,它会自动转到脚本并将我重定向到失败页面的成功。 我试图在重定向后休眠,但它只是等待几秒钟,然后运行脚本并将我重定向到 html 页面。
header('Location: /loading.html');
include ("file\where\the\variable\comes\from.php");
$s = shell_exec("powershell path\\to\\script.ps1 '$variable'< NUL");
if (strpos($s, 'True') === false) {
header('Location: /succes.html');
}
else{
header('Location: /failed.html');
}
【问题讨论】:
-
你错过了
exit();。您的脚本在您的第一个header()处死去,因为它感觉需要重定向,但由于未知结束而无法继续。您include()或require_once()您的加载页面,然后在每个header()方法之后添加一个exit();。 See how it should be here -
为什么你要先使用重定向,而且只有在你在 shell 脚本中调用重定向之后才使用重定向?据我所知,这里发生的是: 1. 服务器将重定向标头发送到浏览器。 (代码中的第一行) 2. 浏览器请求 loading.html 3. 服务器向浏览器发送 loading.html 脚本的其余部分将保持未执行状态。
标签: php powershell redirect shell-exec