tarun Posted April 8, 2007 Share Posted April 8, 2007 <?php $user = $_POST["u"]; $pass = $_POST["p"]; $db = file("db.txt"); foreach($db as $key => $val) { $data[$key] = explode("|-|", $val); } for($k = 0; $k < sizeof($db); $k++) { $u = $data[$k][0]; $p = $data[$k][1]; if ( $u == "$user" ) { if ( $p == "$pass" ) { echo 'You Are Now Logged In As: '.$u.''; } else { echo 'Username And Password Do Not Match'; } } } ?> Theres Still More To Add When Your Logged In Such As Sessions But At The Moment I Can't Even Log In I Get My Error "Username And Password Do Not Match" Quote Link to comment Share on other sites More sharing options...
tarun Posted April 10, 2007 Author Share Posted April 10, 2007 BuMp Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 10, 2007 Share Posted April 10, 2007 You're "if" is incorrect, try: <?php if ( $u == $user && $p == $pass) echo 'You Are Now Logged In As: '.$u; else echo 'Username And Password Do Not Match'; ?> BTW, what is the format of your input file? There may be an easier way of doing this. Ken Quote Link to comment Share on other sites More sharing options...
tarun Posted April 10, 2007 Author Share Posted April 10, 2007 By Input File Do You Mean The db.txt File It Looks Similar To This user1|-|pass1 user2|-|pass2 And With This "NEW" Code I Get: Username And Password Do Not MatchUsername And Password Do Not Match It Comes Out Twice Because There Are Two Columns Of Data (eg. Col1:user1 Col2:pass1) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 10, 2007 Share Posted April 10, 2007 Ok. Go back to your original "if" statement. I believe the problem is that you're not trimming off the newline character from the end of the input lines before you do the compare. Change: <?php foreach($db as $key => $val) { $data[$key] = explode("|-|", $val); }?> to <?php for ($i=0;$i<count($db);$i++) $data[] = explode("|-|", trim($db[$i]); ?> Here is my version of your code that I tested to make sure it worked: <?php $user = $_POST["u"]; $pass = $_POST["p"]; $data = array(); $db = file("db.txt"); for ($i=0;$i<count($db);$i++) $data[] = explode("|-|", trim($db[$i])); for($k = 0; $k < count($data); $k++) { if ( $data[$k][0] == $user ) if ( $data[$k][1] == $pass ) echo 'You Are Now Logged In As: '.$user; else echo 'Username And Password Do Not Match'; } ?> Ken Quote Link to comment Share on other sites More sharing options...
tarun Posted April 10, 2007 Author Share Posted April 10, 2007 Thnx Works Like A Charm Now... Quote Link to comment 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.