Flaki Posted May 21, 2008 Share Posted May 21, 2008 Hi folks I have some problems. When I type the wrong password or username i can still log in. Is there anything wrong with this code, any typos? If not, can I possible change the else statement, like connecting to another side if the password is wrong? <form action=projekt2.php method=POST> <----------- when the pass is korrekt, it shall go to projekt.php. Username <input type=text name=user><br/> Password <input type=password name=pass> <input type=submit value="bekräfta"><p> </form> <?php $user=$_POST['user']; $pass=$_POsT['pass']; if (($user=="Adrian") && ($pass=="hello")) echo "yes"; elseif (($user=="Janoo") && ($pass=="bye")) echo "yes"; else echo "no"; <----------- change to connect to another side, like Google for instance? ?> ------------------------------------------------------------------------------------------- The first thing I wanted to do was to make a page before the login page. Here you shall write your name. It will be displayed on login.php. If names like "adrian" are typed it shall display "Hi Adrian, you're the GOD", although it does not work, whats missing? <form action="login.php" method="POST"> write your name: <input type="text" name="name" /> <input type="submit" value="puss this button to go to login section" /> </form> ----------------------------------------------------------------------------- // this is on login.php Hi <?php echo $_POST["namn"]; $person=$_POST['namn']; if ($person=="Adrian") echo "Hi Adrian, you're the GOD"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/ Share on other sites More sharing options...
marcusfaye87 Posted May 21, 2008 Share Posted May 21, 2008 Hi folks I have some problems. When I type the wrong password or username i can still log in. Is there anything wrong with this code, any typos? If not, can I possible change the else statement, like connecting to another side if the password is wrong? <form action=projekt2.php method=POST> Username <input type=text name=user> Password <input type=password name=pass> <input type=submit value="bekräfta"><p> </form> <?php $user=$_POST['user']; $pass=$_POsT['pass']; if (($user=="Adrian") && ($pass=="hello")) echo "yes"; elseif (($user=="Janoo") && ($pass=="bye")) echo "yes"; else echo "no"; <----------- change to connect to another side, like Google for instance? ?> ------------------------------------------------------------------------------------------- The first thing I wanted to do was to make a page before the login page. Here you shall write your name. It will be displayed on login.php. If names like "adrian" are typed it shall display "Hi Adrian, you're the GOD", although it does not work, whats missing? <form action="login.php" method="POST"> write your name: <input type="text" name="name" /> <input type="submit" value="puss this button to go to login section" /> </form> ----------------------------------------------------------------------------- // this is on login.php Hi <?php echo $_POST["namn"]; $person=$_POST['namn']; if ($person=="Adrian") echo "Hi Adrian, you're the GOD"; ?> (just making it more readable) Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/#findComment-546870 Share on other sites More sharing options...
prcollin Posted May 21, 2008 Share Posted May 21, 2008 I think maybe it has someting to do with calling the Name field user in the html then trying to _get it as namn (which is spelled wrong anyway) Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/#findComment-546874 Share on other sites More sharing options...
marcusfaye87 Posted May 21, 2008 Share Posted May 21, 2008 login.php <form action=login.php method=POST> Username <input type=text name=user> Password <input type=password name=pass> <input type=submit name="submit" value="bekräfta"><p> </form> login Check:<br> <?php if (isset ($_POST['submit'])) { $username = $_POST['user']; $password = $_POST['pass']; if ($username == "Adrian" && $password == "hello") { echo "yes"; } elseif ($username == "Janoo" && $password == "bye") { echo "yes"; } else { echo "<script language='javascript'>window.location='http://www.google.com/';</script>"; } } ?> An example of what you might be looking for Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/#findComment-546875 Share on other sites More sharing options...
Flaki Posted May 21, 2008 Author Share Posted May 21, 2008 I think maybe it has someting to do with calling the Name field user in the html then trying to _get it as namn (which is spelled wrong anyway) This part is fixed, thanks! (just making it more readable) Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/#findComment-546878 Share on other sites More sharing options...
marcusfaye87 Posted May 21, 2008 Share Posted May 21, 2008 I think maybe it has someting to do with calling the Name field user in the html then trying to _get it as namn (which is spelled wrong anyway) This part is fixed, thanks! (just making it more readable) Thanks a lot! I replied with actual code after that Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/#findComment-546880 Share on other sites More sharing options...
Flaki Posted May 21, 2008 Author Share Posted May 21, 2008 I replied with actual code after that This is excellent work! It's simple and educational for newbies like me! Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/#findComment-546886 Share on other sites More sharing options...
Flaki Posted May 21, 2008 Author Share Posted May 21, 2008 login.php <form action=login.php method=POST> Username <input type=text name=user> Password <input type=password name=pass> <input type=submit name="submit" value="bekräfta"><p> </form> login Check:<br> <?php if (isset ($_POST['submit'])) { $username = $_POST['user']; $password = $_POST['pass']; if ($username == "Adrian" && $password == "hello") { echo "yes"; } elseif ($username == "Janoo" && $password == "bye") { echo "yes"; } else { echo "<script language='javascript'>window.location='http://www.google.com/';</script>"; } } ?> An example of what you might be looking for Hmm the code looks neat but it doesn't work as it should do, it doesn't go to Google if I type wrong. I'm using linux/xampp by the way. Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/#findComment-546898 Share on other sites More sharing options...
DeanWhitehouse Posted May 21, 2008 Share Posted May 21, 2008 change this echo "<script language='javascript'>window.location='http://www.google.com/';</script>"; to header ("http://google.com"); then put ob_start(); at the begining of the script Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/#findComment-546899 Share on other sites More sharing options...
marcusfaye87 Posted May 21, 2008 Share Posted May 21, 2008 There are 2 options: Option 1: Your browser does not support JavaScript or it is blocked Option 2: You've implemented it wrong, make the code an entirely new file called "login.php", then try running it. Quote Link to comment https://forums.phpfreaks.com/topic/106679-help-with-a-simpel-login-code/#findComment-546900 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.