douqiaolong0528 2017-06-21 12:48
浏览 60
已采纳

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

in PHP how can I redirect my page once scrpit has run with a successful case 0 but stay on current page for anything else?

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条回答 默认 最新

  • dongtun1872 2017-06-21 12:54
    关注

    If you don't mind removing your "echo" before the redirect you can redirect with header

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

    If not you can use javascript

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

    And you could add something to delay the redirect or put your "successfully exported" message on an alert before the redirect, otherwise the user might not see the message if the redirect works too fast.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动