Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/76639-solved-login-thing/
Share on other sites

Hmm...I only see one post here. :shrug:

 

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.

Link to comment
https://forums.phpfreaks.com/topic/76639-solved-login-thing/#findComment-388039
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.