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");
}
?>
Run Code Online (Sandbox Code Playgroud)
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>';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
195 次 |
| 最近记录: |