forumnz Posted January 1, 2007 Share Posted January 1, 2007 I have a user login/logout section. On another section I have a part where the user doesnt need to be logged in... but i want a piece of text up the top to read "Login" when thay arent, and "Logout" when they are.So far I just have "Login"This is the small piece of PHP that should do it for me...[code]<?php if (!$_SESSION['username']) { echo('Log In'); } else { echo('Log Out'); } ?>[/code]Thanks. Link to comment https://forums.phpfreaks.com/topic/32474-solved-i-have-a-small-problem-to-do-with-sessions/ Share on other sites More sharing options...
forumnz Posted January 1, 2007 Author Share Posted January 1, 2007 Can anyone help? Link to comment https://forums.phpfreaks.com/topic/32474-solved-i-have-a-small-problem-to-do-with-sessions/#findComment-150850 Share on other sites More sharing options...
JasonLewis Posted January 1, 2007 Share Posted January 1, 2007 make sure you are using session_start(); at the very top of your page, no spaces... nothing between it...also, remove your brackets in your echo, that is not good coding practise... and i would use isset in the if statement...[code=php:0]if(!isset($_SESSION['username'])){echo "Log In";}else{echo "Log Out";}[/code]:) Link to comment https://forums.phpfreaks.com/topic/32474-solved-i-have-a-small-problem-to-do-with-sessions/#findComment-151001 Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Share Posted January 1, 2007 [quote author=ProjectFear link=topic=120588.msg494852#msg494852 date=1167689975]make sure you are using session_start(); at the very top of your page, no spaces... nothing between it...also, remove your brackets in your echo, that is not good coding practise... and i would use isset in the if statement...[code=php:0]if(!isset($_SESSION['username'])){echo "Log In";}else{echo "Log Out";}[/code]:)[/quote]according to my experience does not the [b]![/b] command mean not. therefore, shouldnt the code be:[code]<?phpsession_start();if(isset($_SESSION['username'])){echo "Log In";}else{echo "Log Out";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32474-solved-i-have-a-small-problem-to-do-with-sessions/#findComment-151003 Share on other sites More sharing options...
JasonLewis Posted January 1, 2007 Share Posted January 1, 2007 no, because then if the session is set you are asking them to login. you wont to ask them to logout of the session IS set, so we do if the session isn't set (!isset) we show login else show logout because the session will be set. Link to comment https://forums.phpfreaks.com/topic/32474-solved-i-have-a-small-problem-to-do-with-sessions/#findComment-151006 Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Share Posted January 1, 2007 [quote author=ProjectFear link=topic=120588.msg494857#msg494857 date=1167690428]no, because then if the session is set you are asking them to login. you wont to ask them to logout of the session IS set, so we do if the session isn't set (!isset) we show login else show logout because the session will be set.[/quote]ohhh i didnt read the topic, kk sorry guys. Link to comment https://forums.phpfreaks.com/topic/32474-solved-i-have-a-small-problem-to-do-with-sessions/#findComment-151010 Share on other sites More sharing options...
JasonLewis Posted January 1, 2007 Share Posted January 1, 2007 you dont really have to read the topic to no that if the user is logged in we ask them if they want to log out. its just logical. but yeh, you gotta look carefully at it. Link to comment https://forums.phpfreaks.com/topic/32474-solved-i-have-a-small-problem-to-do-with-sessions/#findComment-151023 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.