Plazman65 Posted March 3, 2006 Share Posted March 3, 2006 HI all, Im working my way through some light reading PHP and MYsql development and Im trying to do this on my website;<?php {if ($_SESSION['MM_Username'])) { echo 'Logged in as' ($_SESSION['MM_Username']).} else {echo 'you are not logged in.<br/>'; do_html_url('login.php'),'Login'); exit; } } ?>I hope I didnt butcher it to bad does anyone see what Im doing wrong? I hope this learning curve gets easier it sure is overwhelming when your starting. Thanks, Michelle Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/ Share on other sites More sharing options...
php_b34st Posted March 3, 2006 Share Posted March 3, 2006 You had a few little errors like putting{,},(,) in unecessary places, try:[code]<?phpif ($_SESSION['MM_Username']){ echo 'Logged in as ' .$_SESSION['MM_Username']}else{ echo 'you are not logged in.<br/>'; do_html_url('login.php', 'Login'); exit;} ?>[/code]*Notice the layout and indentations, it makes your code much easier to read Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/#findComment-13954 Share on other sites More sharing options...
Plazman65 Posted March 3, 2006 Author Share Posted March 3, 2006 [!--quoteo(post=351379:date=Mar 3 2006, 09:23 AM:name=php_b34st)--][div class=\'quotetop\']QUOTE(php_b34st @ Mar 3 2006, 09:23 AM) [snapback]351379[/snapback][/div][div class=\'quotemain\'][!--quotec--]You had a few little errors like putting{,},(,) in unecessary places, try:[code]<?phpif ($_SESSION['MM_Username']){ echo 'Logged in as ' .$_SESSION['MM_Username']}else{ echo 'you are not logged in.<br/>'; do_html_url('login.php', 'Login'); exit;} ?>[/code]*Notice the layout and indentations, it makes your code much easier to read[/quote]Your right it sure does, thank you for responding, its still not working though. Im wondering if the first line is my problem. if ($_SESSION['MM_Username']) -The first line checks to see if theres a value for MM_Username right?Im having one of those days and want to make sure Thanks, Michelle Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/#findComment-14020 Share on other sites More sharing options...
TylerL Posted March 4, 2006 Share Posted March 4, 2006 Yeah it checks if its a value or if its empty. Also, place: session_start(); at the top of your file, or else you can't use sessions. Try that, if it doesnt work let me know and I have a few other ideas as to what it might be. Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/#findComment-14030 Share on other sites More sharing options...
Plazman65 Posted March 4, 2006 Author Share Posted March 4, 2006 [!--quoteo(post=351459:date=Mar 3 2006, 04:01 PM:name=TylerL)--][div class=\'quotetop\']QUOTE(TylerL @ Mar 3 2006, 04:01 PM) [snapback]351459[/snapback][/div][div class=\'quotemain\'][!--quotec--]Yeah it checks if its a value or if its empty. Also, place: session_start(); at the top of your file, or else you can't use sessions. Try that, if it doesnt work let me know and I have a few other ideas as to what it might be.[/quote]hmmm so what are those ideas you got? I know that the session variables are working because I have been using- <?php echo "Welcome ". $_SESSION['MM_Username'] ."! YOU ARE CURRENTLY LOGGED IN!<br /><br />" ?>;I just dont like the login here link showing up when someone is already logged in, teach me to be picky hahaThanks for the help, Michelle Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/#findComment-14051 Share on other sites More sharing options...
Plazman65 Posted March 4, 2006 Author Share Posted March 4, 2006 OK I got the first part working, woohooo the ; was missing from one of the lines.Now the do_html part isnt working, I definately dont know anything about that part, any ideas?I just dont like the login here link showing up when someone is already logged in, teach me to be picky.I would like it to do,Welcome back 'me' you are logged in. Log out here(with that being a log out link)' ( I havent started working on the logout here part, one challenge at a time)and then when they are logged out it says, Hey you your not logged in log in here (log in here link)( Ok maybe not really say that but you get my point)Thanks for any help you can provide, Michelle Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/#findComment-14105 Share on other sites More sharing options...
php_b34st Posted March 5, 2006 Share Posted March 5, 2006 Can you post some code? because with the code i posted it should only show the login link if the user isnt logged in. Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/#findComment-14295 Share on other sites More sharing options...
Plazman65 Posted March 5, 2006 Author Share Posted March 5, 2006 [!--quoteo(post=351726:date=Mar 4 2006, 04:08 PM:name=php_b34st)--][div class=\'quotetop\']QUOTE(php_b34st @ Mar 4 2006, 04:08 PM) [snapback]351726[/snapback][/div][div class=\'quotemain\'][!--quotec--]Can you post some code? because with the code i posted it should only show the login link if the user isnt logged in.[/quote]<?phpif ($_SESSION['MM_Username']){echo 'Logged in as ' .$_SESSION['MM_Username'];}else{echo 'you are not logged in. Login Here<br/>';do_html_url('loginpage.php', 'Login');exit;} ?>Thats what I got so far, everything from the "Login Here<br/>';" isnt working. Thanks for your help, Michelle Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/#findComment-14325 Share on other sites More sharing options...
php_b34st Posted March 5, 2006 Share Posted March 5, 2006 If thats the only code you have so far the problem will be because you have not defined the function "do_html_url()" and you will get an error that looks something like "Fatal error: Call to undefined function do_html_url() in your script location on line 9" if you are just starting to learn php I would replace the function with something a bit simplier like a standard hyperlink so your code would look like:[code]<?phpif ($_SESSION['MM_Username']){ echo 'Logged in as ' .$_SESSION['MM_Username'];}else{ echo 'you are not logged in. Login Here<br/>' .'<a href="login.php">Login</a>'; exit;}?>[/code]Then you can always read up on functions later. Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/#findComment-14394 Share on other sites More sharing options...
Plazman65 Posted March 5, 2006 Author Share Posted March 5, 2006 thanks so much Ill try that, I figured it was something to do with the function stuff and no I have gotten to that "chapter" yet. I would be so lost without these forums thats for sure, thanks everybody Quote Link to comment https://forums.phpfreaks.com/topic/4025-logged-in-as/#findComment-14404 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.