重定向然后执行
Redirect then execute
我正在尝试转到加载页面,然后执行 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');
}
在此构造中无法加载页面,因为您的页面仅在文件加载完成后显示。如果您 运行 通过 AJAX 请求包含 / shell 它会。下面的解决方案是 运行 向文件 request.php 发出 AJAX 请求并将其内容复制到 loading.html 的内容中的索引页 (loading.html)。
loading.html
<!-- Your loading.html content --->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$.post( "request.php", function( data ) {
$( "body" ).html( data );
});
</script>
request.php
include ("file\where\the\variable\comes\from.php");
$s = shell_exec("powershell path\to\script.ps1 '$variable'< NUL");
if (strpos($s, 'True') === false) {
echo file_get_contents('succes.html');
}
else {
echo file_get_contents('failed.html');
}
我正在尝试转到加载页面,然后执行 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');
}
在此构造中无法加载页面,因为您的页面仅在文件加载完成后显示。如果您 运行 通过 AJAX 请求包含 / shell 它会。下面的解决方案是 运行 向文件 request.php 发出 AJAX 请求并将其内容复制到 loading.html 的内容中的索引页 (loading.html)。
loading.html
<!-- Your loading.html content --->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$.post( "request.php", function( data ) {
$( "body" ).html( data );
});
</script>
request.php
include ("file\where\the\variable\comes\from.php");
$s = shell_exec("powershell path\to\script.ps1 '$variable'< NUL");
if (strpos($s, 'True') === false) {
echo file_get_contents('succes.html');
}
else {
echo file_get_contents('failed.html');
}