AlanB09 Posted December 13, 2009 Share Posted December 13, 2009 hi there, im new to PHP and this is my attempt at a very basic login authentication. i can get the first 'IF' to run, but the else if doesnt seem to want to work LOL. i wonder if any one can help with this please? i will post the form first.. .. this is called test. <html> <head> <title> More on Variables</title> </head> <body> <form id="login" method="POST" action="logins.php"><br /> Username: <input type="text" name="user" value="user" /><br /> Password: <input type="password" name="password"" /><br /> <input type="submit" value="submit" name="Submit" /><br /> </form> </body> </html> and now the script.. in a file called logins.php <html> <body> <?php // Retrieves the username posted in the form and sets the password $password="Enter"; $username=$_POST['user']; if($username == "Alan" AND $password == "Enter"){ print("Welcome back $username"); } else if($_POST['user'] == "Mel" AND $password == "Laura"){ print("Access Granted, Hiya Pal"); } else { print("Access Denied"); } ?> </body> </html> once again, thank you for any help please keep very basic as i'm just beginning to get to grips with things. Quote Link to comment https://forums.phpfreaks.com/topic/184936-basic-login-authentication-help/ Share on other sites More sharing options...
phpfan101 Posted December 13, 2009 Share Posted December 13, 2009 $password="Enter"; You made it = Enter, so Mel can never login.... it needs to = $_POST['password']; $password=$_POST['password']; Quote Link to comment https://forums.phpfreaks.com/topic/184936-basic-login-authentication-help/#findComment-976276 Share on other sites More sharing options...
AlanB09 Posted December 13, 2009 Author Share Posted December 13, 2009 $password="Enter"; You made it = Enter, so Mel can never login.... it needs to = $_POST['password']; $password=$_POST['password']; thank you very much .. simple logic, i cant believe i didnt see that... i have to say every time i feel like im getting somewhere, i get confused and have to start all over again lol ! Quote Link to comment https://forums.phpfreaks.com/topic/184936-basic-login-authentication-help/#findComment-976282 Share on other sites More sharing options...
phpfan101 Posted December 13, 2009 Share Posted December 13, 2009 i was the same way a few weeks ago when i started Quote Link to comment https://forums.phpfreaks.com/topic/184936-basic-login-authentication-help/#findComment-976283 Share on other sites More sharing options...
AlanB09 Posted December 13, 2009 Author Share Posted December 13, 2009 lol i know this is going to be really really useful which is why ive kept going but honestly ive been banging my head off a wall lmao !! i take it a login script like that wouldnt be very secure though ? Quote Link to comment https://forums.phpfreaks.com/topic/184936-basic-login-authentication-help/#findComment-976285 Share on other sites More sharing options...
oni-kun Posted December 13, 2009 Share Posted December 13, 2009 lol i know this is going to be really really useful which is why ive kept going but honestly ive been banging my head off a wall lmao !! i take it a login script like that wouldnt be very secure though ? You may want to use $password = mysql_real_escape_string($_POST['password']); To sanitize the input against SQL injections (if you were to have a database, per say.) The next step I guess that you'd want to learn is sessions, which allow a logged in person to persist logged in, sessions are pretty simple. Quote Link to comment https://forums.phpfreaks.com/topic/184936-basic-login-authentication-help/#findComment-976290 Share on other sites More sharing options...
phpfan101 Posted December 13, 2009 Share Posted December 13, 2009 no, thats FAR from secure try looking into using mysql databases to store information on w3schools.com or www.tizag.com, or just google some tutorials, and practice then, you can take a look into storing the sessions Quote Link to comment https://forums.phpfreaks.com/topic/184936-basic-login-authentication-help/#findComment-976292 Share on other sites More sharing options...
AlanB09 Posted December 13, 2009 Author Share Posted December 13, 2009 phpfan and oni thank you this is exactly what i need.. a sense of direction! ive gone over variables, operators, etc etc about 100 times, but i need direction lol! simple login in is the start.. next is how to redirect it to my webpage once logged in and im thinking i may need to write a register script lmao !! (uhoooh sql here i come too! ) Quote Link to comment https://forums.phpfreaks.com/topic/184936-basic-login-authentication-help/#findComment-976297 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.