I've created a test flat file called "users.dat". It has a three simple username password combinations separated by commas on three separate lines, like:
username1,password1
username2,password2
etc.
I've also created a simple php form to capture login in information. I'm having a terrible time figuring out how to use file manipulation to read the .dat file and authenticate the username passwords. For the purposes of my experiment, I'm not using any databases yet. My code for the authentication page looks something like this:
So, I'm opening the file, keeping the file open to have it read until the end, then trying a simple if statement to test to see if the file is true. This is as far as I've gotten on my own. Any suggestions in the right direction?
Thanks in advance,
W!
username1,password1
username2,password2
etc.
I've also created a simple php form to capture login in information. I'm having a terrible time figuring out how to use file manipulation to read the .dat file and authenticate the username passwords. For the purposes of my experiment, I'm not using any databases yet. My code for the authentication page looks something like this:
Code:
?php
$username = $_POST['username'];
$password = $_POST['password'];
$file = "users.dat";
$fp = fopen($file, "r");
while(!feof($fp)) {
$data = fgets($fp, 1024);
}
if ((file_exists($username)) && (file_exists($username))){
echo "Thank you, $username for logging in.";
}
else {
echo "You will need to register.";
}
fclose($fp);
?>
So, I'm opening the file, keeping the file open to have it read until the end, then trying a simple if statement to test to see if the file is true. This is as far as I've gotten on my own. Any suggestions in the right direction?
Thanks in advance,
W!