Re: problem using &&

From: Date: Wed, 26 Jul 2006 15:11:29 +0000
Subject: Re: problem using &&
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-239820@lists.php.net to get a copy of this message
On Wed, 26 Jul 2006 17:01:51 +0200, Jochem Maas <jochem@iamjochem.com> wrote: >> I sure wont. >> On the topic of my array, what would be an efficient way of checking my > username/passwordd pairs match the user input form my login form. >> The text file contains username and passwords in the following format: >> username1,password1 >> username2,password2 > > I dunno, something like this maybe: > > $u = trim($_POST['usr']); > $p = trim($_POST['pwd']); > > $lines = file('/you/pwd/file'); > $users = array(); > foreach ($lines as $line) { > list($usr, $pwd) = explode(',',$line); > $users[ $usr ] = $pwd; > } > > if (isset($users[ $u ]) && ($users[ $u ] === $p)) { > echo "Found {$u}, and password is correct."; > } That works very well. Thanks Jochem. Eoghan

« previous php.general (#239820) next »