Hello everyone, I've created a login page, where you enter your username and password, it checks the database and if it matches then you go to another page else you will get a Wrong username or password error. I've got three files login.php check_login.php login_success.php You enter username and password in login.php and it goes to check_login.php and validates it if it is correct you will go to login_success.php else you will get the error. I can't go directly to check_login.php because I will get error but if directly go to login_sucess.php I don't get the error, although here is the code I have in it. I'm supposed to get redirected to login.php but instead I see login successful. Here is the code I have in check_login.php That is not the full but it is for registering the sessions. Any info what do I do with this? Regards,
Your using this ? http://www.phpeasystep.com/workshopview.php?id=6 Are you using the correct file for your php version ?
Hi, I've just re-wrote it and tested it on PHP5 - This should work. <?php if(!isset($_SESSION['username'])) { header("Location: login.php"); } else { ?> <html> <body> Login Successful </body> </html> <?php } ?> Code (markup): There shouldn't be a need for session_start(); in the login check because if the user has logged in the session will already be set.
You need the session_start or else the session is lost. Try this for login_success <?php session_start(); if (session_is_registered(username)) { echo '<html><body>Login Successful!</html></body'; } else { header("Location: login.php"); } ?> Code (markup):