Grant132 Posted February 25, 2007 Share Posted February 25, 2007 Hey.. I've been playing with this script for a few hours this morning and i can't find whats wrong with it... <?php session_start(); $user = $_POST['username']; $pass = $_POST['password']; $details = file("flat_file_database.php"); foreach($details as $key => $Val) { $data[$key] = explode("||", $Val); } for($k = 0; $k < sizeof($details); $k++) { $u = $data[$k][0]; $p = $data[$k][1]; if($user == $u && $pass == $p) { $_SESSION['user'] = $user; $_SESSION['logged'] = "yes"; $_SESSION['test'] = "1"; include("news.php"); }else{ print "username or pass was incorrect"; } } ?> When i go to login gives me the username or pass was incorrect error, even though the details i use are exact from the flat file db. If anyone sees where ive gone wrong could you please let me know =D Thanks in advanced, Grant Link to comment https://forums.phpfreaks.com/topic/39981-flat-file-login/ Share on other sites More sharing options...
superuser2 Posted February 25, 2007 Share Posted February 25, 2007 Let's see flat_file_database.php. Chances are you aren't getting the values correctly. Link to comment https://forums.phpfreaks.com/topic/39981-flat-file-login/#findComment-193344 Share on other sites More sharing options...
Grant132 Posted February 25, 2007 Author Share Posted February 25, 2007 flat_file_database.php: user1||password user1||pass etc||etc Link to comment https://forums.phpfreaks.com/topic/39981-flat-file-login/#findComment-193346 Share on other sites More sharing options...
Grant132 Posted February 25, 2007 Author Share Posted February 25, 2007 hmm i tried taking out the "&& $pass == $p and it worked perfectly: <?php session_start(); $user = $_POST['username']; $pass = $_POST['password']; $details = file("db.php"); foreach($details as $key => $Val) { $data[$key] = explode("||", $Val); } for($k = 0; $k < 1; $k++) { $u = $data[$k][0]; $p = $data[$k][1]; if($user == $u) { $_SESSION['user'] = $user; $_SESSION['pass'] = $pass; $_SESSION['logged'] = "yes"; $_SESSION['test'] = "1"; include("news.php"); }else{ print "username or pass was incorrect"; } } ?> does that help at all? Link to comment https://forums.phpfreaks.com/topic/39981-flat-file-login/#findComment-193394 Share on other sites More sharing options...
Grant132 Posted February 25, 2007 Author Share Posted February 25, 2007 ok scrap that... <?php session_start(); $user = $_POST['username']; $pass = $_POST['password']; $details = file("db.php"); foreach($details as $key => $Val) { $data[$key] = explode("||", $Val); } for($k = 0; $k < 1; $k++) { $u = $data[$k][0]; $p = $data[$k][1]; if($user == $u && $pass == $p) { $_SESSION['user'] = $user; $_SESSION['pass'] = $pass; $_SESSION['logged'] = "yes"; $_SESSION['test'] = "1"; include("news.php"); }else{ print "username or pass was incorrect"; } } ?> and user1||password|| user1||pass|| (the extra || on the end) that works however it only works for the first combination.. Link to comment https://forums.phpfreaks.com/topic/39981-flat-file-login/#findComment-193396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.