Lynx992 Posted February 7, 2012 Share Posted February 7, 2012 Hello guys, before I start I'm a relativity new user of PHP so this really could be something extremely simple, I just can't seem to find it, Basically on my website i have php login script, when you're logged on every page you visit checks a file called auth.php, This will tell create a session called, "$SESSION" Inventive i know... That will tell the browser if the user is logged in or not, so it can decide whether or not to create a Login button, or a Log out button, Here's the code i have so far. if ( $SESSION == '' ) { echo "<a href='logout.php" ."Log out"; } else { echo "<a href='login-form.php" ."Log in"; } Now, I believe i'm on the right lines? But i'm not fully sure how to basically in English say, If that session is working or exists, Then do this, if not, do this. I mention again, I'm very new to PHP so any help would be very appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/256631-if-session-active-else/ Share on other sites More sharing options...
spiderwell Posted February 7, 2012 Share Posted February 7, 2012 in order to access any session variables on a page, you have to first activate that session on each page that you want to access it. session_start(); now if you have logged in someone successfully already, lets assume they have a value in the session to confirm this, for instance $_SESSION['logged'] = true; so when it comes to the button bit, make sure the page has the session start bit, then do the if statement like this if($_SESSION['logged']) { echo 'logout'; } else { echo 'login' } Quote Link to comment https://forums.phpfreaks.com/topic/256631-if-session-active-else/#findComment-1315596 Share on other sites More sharing options...
Lynx992 Posted February 7, 2012 Author Share Posted February 7, 2012 Thanks a lot for the help Working fine now, Thanks again. Much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/256631-if-session-active-else/#findComment-1315600 Share on other sites More sharing options...
spiderwell Posted February 7, 2012 Share Posted February 7, 2012 happy to help, hit the solved button! Quote Link to comment https://forums.phpfreaks.com/topic/256631-if-session-active-else/#findComment-1315604 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.