I am stuck.
I have a login form where a person will enter the email and password for their account. The data is being stored in a registereduser.txt file. Each item is seperated with a colon. The data is written in to the file
fwrite ($fp, "$email:$pw:$fname:$lname\n");
This is working fine.
What I am trying to create is a function that will take what they enter on the login page and check the information in the txt file to confirm the login information. My initial problem was that it never found a match even when there was some. So I checked to see if it was reading the file and it is. Now I am getting an error at the foreach() function I am using and then it does not find a match and the code ends. Here is the result I am getting:
seebetra@hvcc.edu:test:Tracy:seebe fdoe@test.com:test:Jane😃oe test@test.com:test:TJ:Kay
Warning: Invalid argument supplied for foreach() in /staff/seebetra/homepage/ciss225/library.pinc on line 14
Sorry, you didn't match!
Here is the function:
<?php
function getLogin($username, $pass)
{
$username = trim($POST['email_address']);
$pass = trim($POST['password']);
$file = "/staff/seebetra/homepage/ciss225/registered_users.txt";
$fp = fopen($file, 'r');
$lines = fread($fp, filesize($file));
echo $lines;
foreach($lines as $line)
{
list($email_address, $password, $first_name, $last_name) = explode(":", trim($line));
$logged = FALSE;
echo $email_address;
echo $password;
echo first_name;
echo $last_name;
if($username == $email_address && $pass == $password)
{
echo "Hello ".$first_name." ".$last_name."!";
$logged = TRUE;
break;
}
}
if(!$logged)
echo "Sorry, you didn't match!";
fclose($fp);
}
?>
Any insight to get me through this would be very much appreciated!