PHP运行脚本然后一旦完成重定向

时间:2017-06-21 12:48:10

标签: php mysql database-backups downloadfile mysql-backup

在PHP中如何在scrpit运行成功案例0后重定向我的页面,但在其他任何地方保留当前页面?

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;
}

1 个答案:

答案 0 :(得分:0)

如果你不介意删除你的回声&#34;在重定向之前,您可以使用标题重定向

 header("Location: http://you-url");

如果没有,你可以使用javascript

<script> window.location = "http://your-url"; </script>

您可以添加一些内容来延迟重定向或将您的&#34;成功导出&#34;重定向之前的警报上的消息,否则如果重定向工作得太快,用户可能看不到消息。