passingTime Posted August 17, 2011 Share Posted August 17, 2011 Hi everyone, I've gotten a login setup on a site and it displays somewhere on every page. What i am trying to do is when someone logins I would like it to be switched to a little control panel showing your name and other things that i am able to setup. I'm just not sure how to switch them, maybe this will help you get an idea of what i mean: if (logged in) { show control panel } else show login Must i use javascript for this? Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/ Share on other sites More sharing options...
JKG Posted August 17, 2011 Share Posted August 17, 2011 no this is the kind of the PHP does. if you want specific help, can you provide specific code? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258601 Share on other sites More sharing options...
passingTime Posted August 17, 2011 Author Share Posted August 17, 2011 Ok So i have a simple login i'm testing with. Which simple is: <form action='login.php' method='post'> <input type="text" name="username" /><br> <input type="password" name="password" /><br> <input type="submit" value="Log in" /> </form> I want this only to show if the user is logged in. If not I want something else shown. Not sure how to do this though. So it'll end up as something like (i think): if(isset($_SESSION['username'])) { echo "welcome"; } else *display the login form* Not sure how to do this though :s Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258624 Share on other sites More sharing options...
JKG Posted August 17, 2011 Share Posted August 17, 2011 what login script are you using? you need to see what login.php is doing. obviously login.php is evaluating wether the user and pass are valid or not. if they are, how does it respond? does it set a cookie? a session? post the login.php code if you like. Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258628 Share on other sites More sharing options...
passingTime Posted August 17, 2011 Author Share Posted August 17, 2011 Everything is still very simple. Right now i'm just using this: <?php session_start (); $username = $_POST['username']; $password = $_POST['password']; if ($username && $password){ $connect = mysql_connect("localhost","root","") or die ("Couldn't connect!"); mysql_select_db("phplogin") or die ("Couldn't find the DB"); $query = mysql_query ("SELECT username && password FROM users WHERE username='$username'"); echo "hello"; } else echo "no username"; Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258631 Share on other sites More sharing options...
JKG Posted August 17, 2011 Share Posted August 17, 2011 hmm are you storing passwords in plain text? i suggest you start from a currently available script. if your struggling with this your gonna hit another roadblock pretty soon! ro scripts login is ok. http://www.roscripts.com/PHP_login_script-143.html scroll to the bottom and click download for v1.2 in the case of this system, to determin what to show to users/non users: <?php if ( $_SESSION['logged_in'] == TRUE ){}else{};?> or admins/users <?php if ( isadmin ( $_SESSION['user_id'] ) ){}else{}; ?> Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258635 Share on other sites More sharing options...
JKG Posted August 17, 2011 Share Posted August 17, 2011 actually, you have to log in and all sorts to download it. if you want it, pm me your email address and ill send it. Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258637 Share on other sites More sharing options...
passingTime Posted August 17, 2011 Author Share Posted August 17, 2011 I'm fine with building a secure form. I just want to remove the login form if someone is logged in. Like on this forum for example, the login is at the top left but once u log in it's replaced with something else. Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258640 Share on other sites More sharing options...
JKG Posted August 17, 2011 Share Posted August 17, 2011 ok.......... <?php session_start (); $username = $_POST['username']; $password = $_POST['password']; if ($username && $password){ $connect = mysql_connect("localhost","root","") or die ("Couldn't connect!"); mysql_select_db("phplogin") or die ("Couldn't find the DB"); $query = mysql_query ("SELECT username && password FROM users WHERE username='$username'"); echo "hello"; $_SESSION['logged_in'] = TRUE; } else echo "no username"; ?> to check: <?php if ( $_SESSION['logged_in'] == TRUE ){}else{};?> Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258642 Share on other sites More sharing options...
JKG Posted August 17, 2011 Share Posted August 17, 2011 your if statement logs them in even if they are not in the db... i was going to do it all for you, but there are so many errors in that it is unreal. take my previous suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258643 Share on other sites More sharing options...
passingTime Posted August 17, 2011 Author Share Posted August 17, 2011 I'm looking at the premade login script u sent me. It's using keys which i haven't learned to do yet... Way more secure than what i would have made. Gonna send you my email, hope you can still it to me Quote Link to comment https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/#findComment-1258648 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.