Checking to see if email is already on file
Posted: Tue Mar 08, 2011 5:43 pm
Hello, I am having trouble with PHP code to check to see when a user signs-up for my site, if the email is already in my email txt file. The text file contains an email address per line. Here's the code that I have been trying to use. However, it always returns false, if I put else {return true;} in it it always returns true! So, here's my code.
Thanks!
Code: Select all
function check_email_exists($email) {
// Check if email already exists
$efile = fopen("data/email_listing.txt", "rb");
$address = fgets($efile);
while(!feof($efile)){
// compare strings, length of first string is the length
if (strncasecmp($email, $address, strlen($email)) == 0) {
return false;
} else {
return true;
}
$address = fgets($efile);
}
fclose($efile);
}