PHP运行脚本,然后重定向一次完成
问题描述:
在PHP中我怎样才能重定向我的网页,一旦scrpit运行成功案例0,但留在当前页面的其他任何东西?PHP运行脚本,然后重定向一次完成
exec($command, $output = array(), $worked);
switch($worked) {
case 0:
echo "Database <b>". $database. "</b> successfully exported to <b>". $filename. '</b>';
// add redirect here
break;
case 1:
echo 'There was a warning during the export of <b>'. $database .'</b> to <b>'. $filename .'</b>';
break;
case 2:
echo 'There was an error during import.'
. 'Please make sure the import file is saved in the same folder as this script and check your values:'
. '<br/><br/><table>'
. '<tr><td>MySQL Database Name:</td><td><b>'. $database .'</b></td></tr>'
. '<tr><td>MySQL User Name:</td><td><b>'. $user .'</b></td></tr>'
. '<tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr>'
. '<tr><td>MySQL Host Name:</td><td><b>'. $host .'</b></td></tr>'
. '<tr><td>MySQL Import Filename:</td><td><b>'. $filename .'</b></td>'
. '</tr></table>'
;
break;
}
答
如果你不介意删除您的“回声”重定向之前,你可以用头重定向
header("Location: http://you-url");
如果不是你可以使用JavaScript
<script> window.location = "http://your-url"; </script>
而且你可以添加在重定向之前延迟重定向或将“成功导出”消息放在警报上,否则如果重定向工作过快,用户可能看不到消息。
在case 0重定向('another_page','refresh'); –
在重定向之前无法回显,因为您会收到错误消息。 –
做它重定向将重定向(“page.php”,“刷新),或完整的URL? – shaggs