kellz Posted November 9, 2007 Share Posted November 9, 2007 hey.. I'm making a kinda thing that people use to login to websites..like yahoo but much MUCH more crappy lol so here it is: if (isset($_POST['Submit']) ) { if (isset($_POST['name']) && isset($_POST['pass'])) { $name = $_POST['name']; $pword = $_POST['pass']; $lines = file('np.txt'); $data = array(); foreach ($lines as $line) { $data = explode(':', $line); $user = $data[0]; $pass = $data[1]; if ($user == $name && $pass == $pword) { echo 'logged in!'; } else { echo 'user name and/or password incorrect'; } unset ($data[0]); unset ($data[1]); } } } the format of the file np.txt is like this: kelsey:password user2:lalalala user3:helloworld but it all messes up and says i am logged in AND im not logged in at the same time with whatever username or password i used. But it's weird because if i leave only 1 line in the np.txt file it all works.. I guess it's the array so I tried unset (not really knowing 100% why i tried it) but I did lol and that done nothing. Quote Link to comment https://forums.phpfreaks.com/topic/76639-solved-login-thing/ Share on other sites More sharing options...
kellz Posted November 9, 2007 Author Share Posted November 9, 2007 OMG the page wasnt loading so i was clicking it more and then it finally worked now i got 2 (or more?) posts lol sooo sorry how do you delete them? Quote Link to comment https://forums.phpfreaks.com/topic/76639-solved-login-thing/#findComment-388036 Share on other sites More sharing options...
KevinM1 Posted November 9, 2007 Share Posted November 9, 2007 Hmm...I only see one post here. Regarding your problem, I'm thinking it has to do with your foreach-loop. The loop won't end if you find the right username:password data -- it'll keep iterating until it runs to the end of the file. Try putting a break in your if-conditional, after you handle a successful login. That may fix the problem. Quote Link to comment https://forums.phpfreaks.com/topic/76639-solved-login-thing/#findComment-388039 Share on other sites More sharing options...
KevinM1 Posted November 9, 2007 Share Posted November 9, 2007 See the solution offered here: http://www.phpfreaks.com/forums/index.php/topic,166977.0.html It's exactly what I recommend. Quote Link to comment https://forums.phpfreaks.com/topic/76639-solved-login-thing/#findComment-388043 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.