duanqin9631 2019-04-12 09:29
浏览 95
已采纳

PHP如何在标题重定向到另一个页面之前回显警报

I'm trying to make a functionality where, after the user logs in, an alert will popup saying "welcome USER_NAME", after which it will redirect to the user profile page.

I tried the sleep & flush methods, and even ob_start & ob_end_flush methods..but nothing seems to work, it just redirects to user profile after logging in without echoing the alert. Is there any way of fixing this problem?

Here is the part of the code:

<?php
if (isset($_SESSION['user'])) {
``$_SESSION['user'] = $uname;
``echo "<script> alert('Welcome $uname')</script>";
``header("location: dashboard.php");
}
?>
  • 写回答

3条回答 默认 最新

  • doudi8298 2019-04-12 09:32
    关注

    PHP's redirection with header("Location:xxx.php"); functionality does not allow any browser output.

    You can use Javascript redirection (taking in consideration of program logic).

    echo '<script>
    alert(' + '"Welcome ' + $uname .'");
    window.location.href="welcome.php";
    </script>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画