etsted Posted February 8, 2014 Share Posted February 8, 2014 every time i log in i get a good message displaying, you have been logged in, but then when i try to click on another link it automatically loges me out why? <?php session_start(); ?> <html> <head> <link href='style/style.css' rel='stylesheet' type="text/css" /> <title>Login</title> <meta name='login' content='login to itsnature' /> <meta name='keywords' content='login' /> </head> <body> <h1>Login</h1> <?php require_once "connect.php"; // sets a navigator if(isset($username)) { include "navigator/navigator_login.php"; } else { include "navigator/navigator.php"; } // login form $login = "<form action='login.php' method='POST' name='login1' class='forgotpass'> <input type='text' name='username' placeholder='Username' /> <br /> <input type='password' name='password' placeholder='Password' /> <input type='submit' name='submit' value='Login' /> | <a href='register.php'>Register</a> </form>"; // includes a navigator if(isset($username)) { echo "<p>Welcome $username.</p> <br />"; } else { if(isset($_POST['username']) && isset($_POST['password'])) { $username = mysqli_real_escape_string($con, $_POST['username']); $password = mysqli_real_escape_string($con, $_POST['password']); } if(isset($username) && isset($password)) { $password = md5($password); $query = mysqli_query($con ,"SELECT * FROM users WHERE username='$username' && password='$password'"); $numrows = mysqli_num_rows($query); if($numrows != 0) { $_SESSION['username'] = $username; echo "<p>You have been logged in.</p> <br />"; } else { echo "<p>Wrong password or username.</p>$login"; } } else { echo "<p>You must register an account in order to login.</p>$login"; } } mysqli_close($con); ?> Link to comment Share on other sites More sharing options...
Mudsaf Posted February 9, 2014 Share Posted February 9, 2014 if(isset($username)) <-- you havent created this variable before & it doesn't exist Do this instead if(isset($_SESSION['username'])) { Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now