runnerjp Posted February 19, 2007 Share Posted February 19, 2007 hey guys i have this [/<?echo $auth[displayname] ?>code] but what do i add to this to display a different message if the user is not logged in like "guest"? Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/ Share on other sites More sharing options...
Greaser9780 Posted February 19, 2007 Share Posted February 19, 2007 I use sessions upon logging into my website. Then on my welcome page you can use an if statement to detect if there is a session for that user. If the user is logged in my pages display Welcome ".$_SESSION['username']." If they are not logged in it can display either please log in or in your case you could have it say "Welcome Guest! Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189008 Share on other sites More sharing options...
runnerjp Posted February 19, 2007 Author Share Posted February 19, 2007 any chance u can put ur code on as an example for me to work with if thats ok ?? Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189013 Share on other sites More sharing options...
desithugg Posted February 19, 2007 Share Posted February 19, 2007 <? if($auth[displayname] == "")// if the variable is empty execute the fallowing { echo"Please login"; } else { echo"Hey logged in as".$auth[displayname]; } ?> Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189016 Share on other sites More sharing options...
Greaser9780 Posted February 19, 2007 Share Posted February 19, 2007 That'll work to. Might need single quotes around that displayname. Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189020 Share on other sites More sharing options...
desithugg Posted February 19, 2007 Share Posted February 19, 2007 oh yeah probably <? if($auth['displayname'] == "")// if the variable is empty execute the fallowing { echo"Please login"; } else { echo"Hey logged in as".$auth['displayname']; } ?> Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189024 Share on other sites More sharing options...
runnerjp Posted February 19, 2007 Author Share Posted February 19, 2007 thanks guys Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189027 Share on other sites More sharing options...
runnerjp Posted February 19, 2007 Author Share Posted February 19, 2007 ok that didnt work :( Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189030 Share on other sites More sharing options...
Greaser9780 Posted February 19, 2007 Share Posted February 19, 2007 Can you post a little more code maybe from the query down to and including what you already posted? Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189032 Share on other sites More sharing options...
runnerjp Posted February 19, 2007 Author Share Posted February 19, 2007 fixed it!! took ['displayname'] and took the --> ' <-- out!! thanks guys Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189034 Share on other sites More sharing options...
Greaser9780 Posted February 19, 2007 Share Posted February 19, 2007 Wow, really. I always get errors when they're not in. Odd. Hey at least you got it though. Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189037 Share on other sites More sharing options...
Jessica Posted February 19, 2007 Share Posted February 19, 2007 You actually need to leave that in and then fix where it's originally set. What you're doing now is a poor coding practice. Read this: http://us3.php.net/manual/en/language.types.array.php Scroll down to : Array do's and don'ts Why is $foo[bar] wrong? Link to comment https://forums.phpfreaks.com/topic/39227-need-to-make-it-so-if-a-users-is-not-logged-in-it-displays-a-different-message/#findComment-189038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.