Hi
I'm trying to search a file in order to find if a userId already exists.
My problem is that when the code runs I get the proper results plus the following notice: Notice: Undefined offset: 1 in a2p8.php on line 68
line 68 is
.
I searched through the web and I found that solution for my problem:
The notice is then disappeared but another problem occurs. Although a userId already exists in the file, a user can choose the same Id and thus I have it in the file twice.
All the code is:
Does anybody know how to solve these problems?
Thanks a lot
I'm trying to search a file in order to find if a userId already exists.
My problem is that when the code runs I get the proper results plus the following notice: Notice: Undefined offset: 1 in a2p8.php on line 68
line 68 is
Code:
list($id,$password) = split(':',$inline);
I searched through the web and I found that solution for my problem:
Code:
list($id,$password) = (is_array($inline))?split(':',$inline):array('','');
The notice is then disappeared but another problem occurs. Although a userId already exists in the file, a user can choose the same Id and thus I have it in the file twice.
All the code is:
Code:
$inf="A2P8.txt";
$FILEH = fopen($inf, 'a+') or die ("Cannot open $inf");
$found=0;
while (!feof($FILEH) && !($found)) {
$inline = fgets($FILEH, 4096);
//list($id,$password) = (is_array($inline))?explode(':',$inline):array('','');
list($id,$password) = split(':',$inline);
if ($id == $userId) {
$found = 1;
}
}
if ($found == 1) {
print "Username: $userId already exists! Please specify another.";
}
else {
$msg="$userId:$pwd"."\r\n";
fputs($FILEH, $msg);
print "Login succefull: userID: $userId, password: $pwd";
}
fclose ($FILEH);
Does anybody know how to solve these problems?
Thanks a lot