Jump to content

Making Welcome Message, Persistent


doubledee

Recommended Posts

I am adding a "Welcome Message" in my Header file - which is included in every page on my website.

 

If the user is logged in, they would see something like, "Welcome, Debbie!!

 

What is the best approach to take with storing (and checking) the "LoggedIn Status" and "User's Name"?

 

Do I just store them both in a SESSION and access them?

 

Or should I be checking for these two values from my back-end database?

 

It seems to me that a couple of weeks ago I got into some big debate with people about "persistence" and whether it was okay of not to store information in the SESSION...

 

What do you think?

 

Thanks,

 

 

Debbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/245655-making-welcome-message-persistent/
Share on other sites

sessions are the way to go

 

Ones someone logged in(1 time you contact the database, and check credentials), you store that in a session . So adding Welcome Debbie, can be just as easy as a simple check.

Is debbie logged in if so echo hello debbie

sessions are the way to go

 

Ones someone logged in(1 time you contact the database, and check credentials), you store that in a session . So adding Welcome Debbie, can be just as easy as a simple check.

Is debbie logged in if so echo hello debbie

 

So in my "log_in2.php", after I authenticate the user, I currently set...

$_SESSION['loggedIn'] = TRUE;
$_SESSION['memberFirstName'] = $memberFirstName;

 

So is it okay to just have something like this in my header file...

 

<?php
$firstName = (isset($_SESSION['memberFirstName']) ? $_SESSION['memberFirstName'] : '');

if ($_SESSION['loggedIn'] == TRUE){
	// Member Welcome.
	echo '<p id="welcome">
		<span class="orangeBold">Hello, ' . $firstName . '!!</span>
		</p>';
}else{
	// Visitor Welcome.
	echo '<p id="welcome">
	<span class="orangeBold">Hello,</span> <a href="#">Sign In</a> to access member-only features and content.
									  Not a Member?  <a href="#">Start Here</a>
	</p>';
}
?>

 

 

Debbie

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.