Isom Posted October 19, 2011 Share Posted October 19, 2011 Alright, so I'm fairly new to PHP coding and I still have a ton to learn, so it's not surprising that I ran into a problem pretty quickly. I've setup a database and even managed to scrap together a SIMPLE member management system. All of it works, but I still need one thing. A lot of sites I visit which allow users to signup have this at the top; Login or Register. Nothing huge, just in the corner, know what I mean? I was wondering how I do this? Also, after someone logs in, how do I change that to show "You are logged in as [username] and then a logout option? Quote Link to comment https://forums.phpfreaks.com/topic/249368-you-are-logged-in-as/ Share on other sites More sharing options...
kney Posted October 19, 2011 Share Posted October 19, 2011 Use sessions.. Im too lazy to come with something fancy so <?php session_start(); if(isset($_POST['Login'])){ $username = $_POST['username']; // if you put your password as md5 in your DB $password = md5($_POST['password']; $sql = "SELECT * FROM tableUsers WHERE userName = '" . $username . "' AND password = '" . $password . "'"; $result = mysql_query($result); $row = mysql_fetch_array($result); $_SESSION['id'] = $row['id']; $_SESSION['username'] = $row['userName']; } if($_GET['action'] == 'logout'){ session_unset(); } // if session is set, show the username if(isset($_SESSION['id'])){ echo "You are logged in as " . $_SESSION['username'] . "<br /><br />"; echo "<a href='login.php?action=logout'>Logout</a>"; }else{ // else you show login or register ?> <a href="login.php">Login</a> or <a href="register.php">Register</a> <form name="loginForm" method="post" action="login.php"> <input type="textbox" name="username" /> <input type="password" name="password" /> <input type="submit" name="Login" value="Login" /> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249368-you-are-logged-in-as/#findComment-1280433 Share on other sites More sharing options...
Isom Posted October 20, 2011 Author Share Posted October 20, 2011 This is what I was looking for and worked as far as registering and logging in are concerned, but after login, instead of showing that I'm logged in, it still shows the Username and password fields along with the options to login and register. Quote Link to comment https://forums.phpfreaks.com/topic/249368-you-are-logged-in-as/#findComment-1280693 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.