John Davidson

php - This login success welcome,(email) keep showing after I logged in, is there any way to show it only once? even when I reload like it will disappear?

0 comments
Message:


<?php
session_start();
if (isset($_SESSION["Email"]))
{
echo '<h1> Login Success, Welcome - ' . $_SESSION["Email"]. '</h1>';
}
?>

This login success welcome,(email) keep showing after I logged in, is there any way to show it only once?
even when I reload like it will disappear? I want this looping to stop please help me.



My Answer:
Yes, you can achieve this by using session variables in PHP.

When the user logs in successfully, you can set a session variable to indicate that the welcome message has been shown. Then, on subsequent page loads, you can check if this session variable is set and only display the welcome message if it hasn't been shown before.

Here's an example of how you can implement this:

php
session_start();

if(isset($_SESSION['welcome_message_shown']) && $_SESSION['welcome_message_shown'] === true) {
// Welcome message has already been shown, do not display it again
} else {
// Display the welcome message
echo "Welcome, " . $_SESSION['email'];

// Set the session variable to indicate that the welcome message has been shown
$_SESSION['welcome_message_shown'] = true;
}


Make sure to replace `$_SESSION['email']` with the actual session variable where you store the user's email after they log in. This way, the welcome message will only be shown once and will not reappear even when the page is reloaded.

Rate this post

4 of 5 based on 2080 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us