desjardins2010 Posted December 8, 2010 Share Posted December 8, 2010 I have a simple login - logout script as it stands working fine.. I can loggin get the proper message, choose to logout get the proper message and all sessions are being destroyed proper.. problem is when I try to go back directly to the member.php page it's given me an error of Notice: Undefined index: username in C:\wamp\www\protek\member.php on line 4 but still also telling me I have to be logged in to view this file <?php session_start(); if ($_SESSION['username']) { echo "Welcome, ".$_SESSION['username']."!<BR>"; echo "<a href=\"logout.php\">LOGOUT</a>"; } else { die("Your Have To Be Logged In To View This Page"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 8, 2010 Share Posted December 8, 2010 You need to use isset to test a variable that might not exist. Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144618 Share on other sites More sharing options...
desjardins2010 Posted December 8, 2010 Author Share Posted December 8, 2010 hmmm can you maybe tell me where and how to use an isset() Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144625 Share on other sites More sharing options...
desjardins2010 Posted December 8, 2010 Author Share Posted December 8, 2010 got it thanks plenty Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144627 Share on other sites More sharing options...
desjardins2010 Posted December 8, 2010 Author Share Posted December 8, 2010 ok, sorry I jumped to conclusion too quick.. I'm not sure where to place the isset(); I had placed in first before the session_start and when refreshing it gave the proper message however now even when you do login you get the same message... so question is where does an isset(); statement get placed in the above php Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144633 Share on other sites More sharing options...
PFMaBiSmAd Posted December 8, 2010 Share Posted December 8, 2010 if (isset($_SESSION['username'])) { Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144636 Share on other sites More sharing options...
desjardins2010 Posted December 8, 2010 Author Share Posted December 8, 2010 ERRRRRR.... dunno what I'm doing wrong? do I have this in the right place? <?php if (isset($_SESSION['username'])) { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href=\"index.php\">GO BACK</a>and try again"; } else { session_start(); if ($_SESSION['username']) { echo "Welcome, ".$_SESSION['username']."!<BR>"; echo "<a href=\"logout.php\">LOGOUT</a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144644 Share on other sites More sharing options...
desjardins2010 Posted December 8, 2010 Author Share Posted December 8, 2010 anybody help? Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144667 Share on other sites More sharing options...
worldcom Posted December 8, 2010 Share Posted December 8, 2010 You must start the session first: <?php session_start(); if (isset($_SESSION['username'])) { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href=\"index.php\">GO BACK</a>and try again"; } else { if ($_SESSION['username']) { echo "Welcome, ".$_SESSION['username']."!<BR> echo "<a href=\"logout.php\">LOGOUT</a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144671 Share on other sites More sharing options...
desjardins2010 Posted December 8, 2010 Author Share Posted December 8, 2010 that is given me now no message and the same error??? Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144675 Share on other sites More sharing options...
desjardins2010 Posted December 8, 2010 Author Share Posted December 8, 2010 isn't calling an isset() kinda repeating what I have already said... orginal script says that if there is a session give them the ok and if no tell them to go back?/ Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144677 Share on other sites More sharing options...
desjardins2010 Posted December 8, 2010 Author Share Posted December 8, 2010 got instead should be using !isset thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144680 Share on other sites More sharing options...
worldcom Posted December 8, 2010 Share Posted December 8, 2010 I should have read that, but you may want to change your code anyway: <?php session_start(); if (isset($_SESSION['username'])) { echo "Welcome, ".$_SESSION['username']."!<BR> echo "<a href=\"logout.php\">LOGOUT</a>"; } else { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href=\"index.php\">GO BACK</a>and try again"; } ?> It just makes a bit more sense Quote Link to comment https://forums.phpfreaks.com/topic/221060-ok-need-a-second-set-of-eyes-here/#findComment-1144682 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.