Athmaus Posted March 24, 2011 Share Posted March 24, 2011 Hello, I created a simple login script, taht has a hard coded user/pass. Yet for some reason it will not work, keeps redirecting to the main login page Here is the code Login Page <table width='400' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td>UserName:</td> <td><form action="loginscript.php" method="post"> <input name="username" type="text" size="10"></td> </tr> <tr> <td>Password:</td> <td><input name="password" type="password" size="10"></td> </tr> <tr> <td colspan='2' align='center'><input name="Submit" type="submit" value="Submit"></form></td> </tr> </table> Login Script <?php session_start(); $pass = strtolower($_POST['password']); $name = strtolower($_POST['username']); if($name == "test" && $pass == "test"){ header ("location: select.php"); } else{ // invalid login, so go back ... header ("location: index.php"); } ?> Select.php <?php session_start(); if(isset($_SESSION['myuser'])){ } else{ header ("location: index.php"); } ?> ANy ideas why it is not working. It doesnt seem like it is going through the login on the loginscript as all it does is redirect back to index page over and over again Quote Link to comment https://forums.phpfreaks.com/topic/231637-simple-login-issues/ Share on other sites More sharing options...
DavidAM Posted March 24, 2011 Share Posted March 24, 2011 if($name == "test" && $pass == "test"){ header ("location: select.php"); } if(isset($_SESSION['myuser'])){ You never actually set a value for $_SESSION['myuser']. Quote Link to comment https://forums.phpfreaks.com/topic/231637-simple-login-issues/#findComment-1191912 Share on other sites More sharing options...
Athmaus Posted March 24, 2011 Author Share Posted March 24, 2011 I cahnged the loginscript to this <?php session_start(); $pass = strtolower($_POST['password']); $name = strtolower($_POST['username']); if($name == "test" && $pass == "test"){ $_SESSION['myuser']=$name; header ("location: select.php"); } else{ // invalid login, so go back ... header ("location: index.php"); } ?> still no luck Quote Link to comment https://forums.phpfreaks.com/topic/231637-simple-login-issues/#findComment-1191914 Share on other sites More sharing options...
DavidAM Posted March 24, 2011 Share Posted March 24, 2011 First, ALWAYS put an exit after any header() redirect. Without the exit(), php will continue running code until the browser actually receives and acts on the redirect. That could be the problem here. loginscript.php <?php session_start(); $pass = strtolower($_POST['password']); $name = strtolower($_POST['username']); if($name == "test" && $pass == "test"){ $_SESSION['myuser']=$name; header ("location: select.php"); exit; } else{ // invalid login, so go back ... header ("location: index.php"); exit; } ?> select.php <?php session_start(); if(isset($_SESSION['myuser'])){ } else{ header ("location: index.php"); exit; } ?> If that does not solve it. Put an echo before each header() that says something like: "In login redirect to index". This will break the redirect, but at least we can figure out whether it is the loginscript header or the select header that is causing the redirect to index.php. Quote Link to comment https://forums.phpfreaks.com/topic/231637-simple-login-issues/#findComment-1191920 Share on other sites More sharing options...
Athmaus Posted March 24, 2011 Author Share Posted March 24, 2011 Hmmm it appears no matter what i type in the form it always fails....for some reason my form isn't picking up the user/pass i inputted..... Quote Link to comment https://forums.phpfreaks.com/topic/231637-simple-login-issues/#findComment-1191933 Share on other sites More sharing options...
Athmaus Posted March 24, 2011 Author Share Posted March 24, 2011 got it to work <?php session_start(); $pass = strtolower($_POST['password']); $name = strtolower($_POST['username']); if ($name == "test" && $pass == "test") { $_SESSION['myuser'] = $name; session_write_close(); header("Refresh: 0; url='select.php'"); } else { // invalid login, so go back ... header("Refresh: 0; url='index.php'"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/231637-simple-login-issues/#findComment-1191937 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.