【问题标题】:PHP run script then redirect once completePHP运行脚本,然后在完成后重定向
【发布时间】:2017-06-21 12:48:09
【问题描述】:

在 PHP 中,一旦脚本以成功的案例 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;
}

【问题讨论】:

  • 写下这一行以防万一 0 redirect('another_page', 'refresh');
  • 你不能在重定向前回显,因为你会得到一个错误。
  • 作为重定向做它是重定向(“page.php”,“刷新);还是完整的url?
  • redirect 如果您在核心 php 中工作,则重定向是代码点火器功能,因此您可能需要使用 header("Location : your full url");

标签: php mysql database-backups mysql-backup


【解决方案1】:

如果您不介意在重定向之前删除“回声”,您可以使用标头重定向

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

如果没有,你可以使用 javascript

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

您可以添加一些东西来延迟重定向或在重定向之前将“成功导出”消息放在警报上,否则如果重定向工作得太快,用户可能看不到消息。

【讨论】:

    猜你喜欢
    • 2011-06-05
    • 2018-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多