doubledee Posted August 25, 2011 Share Posted August 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/245655-making-welcome-message-persistent/ Share on other sites More sharing options...
cssfreakie Posted August 25, 2011 Share Posted August 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/245655-making-welcome-message-persistent/#findComment-1261690 Share on other sites More sharing options...
doubledee Posted August 25, 2011 Author Share Posted August 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/245655-making-welcome-message-persistent/#findComment-1261701 Share on other sites More sharing options...
MasterACE14 Posted August 25, 2011 Share Posted August 25, 2011 yep that's fine. Quote Link to comment https://forums.phpfreaks.com/topic/245655-making-welcome-message-persistent/#findComment-1261702 Share on other sites More sharing options...
gizmola Posted August 25, 2011 Share Posted August 25, 2011 Agree with freakie and masterace. Quote Link to comment https://forums.phpfreaks.com/topic/245655-making-welcome-message-persistent/#findComment-1261734 Share on other sites More sharing options...
doubledee Posted August 25, 2011 Author Share Posted August 25, 2011 Agree with freakie and masterace. Thanks guys!!! Debbie P.S. Feel free to stop by my thread http://www.phpfreaks.com/forums/index.php?topic=342379.new;topicseen#new which deals with the next steps in my Log-In module. Quote Link to comment https://forums.phpfreaks.com/topic/245655-making-welcome-message-persistent/#findComment-1261735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.