gergy008 Posted May 31, 2009 Share Posted May 31, 2009 I need help with sessions... How do I get it so when you are not logged in, It says login or register in the corner but if you are it says who you are logged in as? I'm learning PHP atm, You can see what I mean by going to http://www.gergy.info Quote Link to comment https://forums.phpfreaks.com/topic/160346-solved-uhh-im-new-to-php-an-i-need-help-with-sessions/ Share on other sites More sharing options...
monkeytooth Posted May 31, 2009 Share Posted May 31, 2009 quick version... <?php if(!$_SESSION['loggedinornot']) { echo "Register | Login"; } else { echo "Welcome back!!"; } ?> changing loggedinornot to match you session id.. Quote Link to comment https://forums.phpfreaks.com/topic/160346-solved-uhh-im-new-to-php-an-i-need-help-with-sessions/#findComment-846148 Share on other sites More sharing options...
MadTechie Posted May 31, 2009 Share Posted May 31, 2009 Heres a basic example When i user logs in, you can set a session like this <?php session_start(); //connect to database and check login details //get UserID eg $row['UserName'] //set to session $_SESSION['UserName'] = $row['UserName']; ?> Now on other pages if that session is set you can check it like this <?php session_start(); if(!empty($_SESSION['UserName'])) { echo "Welcome Guest <a href=\"login.php\">Login</a>"; }else{ echo "Welcome ".$_SESSION['UserName']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160346-solved-uhh-im-new-to-php-an-i-need-help-with-sessions/#findComment-846149 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.