Checking to see if email is already on file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrondo
Forum Newbie
Posts: 1
Joined: Tue Mar 08, 2011 5:36 pm

Checking to see if email is already on file

Post by mrondo »

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.

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);
    }
Thanks!
Post Reply