Jump to content

email validation


Pavlos1316

Recommended Posts

Hello,

 

I have the below register.php file

 

//database info

//database connection

//check if username is empty
exit();
}

//check  ...
...  password is empty
exit();
}

//check if username exists
exit();
}

//check if captcha is the same as the provided
exit();
}

//post to database

 

Where ever I put the email validation code (as it is) it doesn't work even if i put 1234 for email, it accepts it.

 

function checkEmail($email) { 
if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) 
return false; 
list($Username, $Domain) = split("@",$email); 
if(getmxrr($Domain, $MXHost)) 
return true; 
else { 
try { 
if(!@fsockopen($Domain, 25, $errno, $errstr, 30)) 
throw new Exception (mysql_error()); 
else 
return true; 
} 
catch (Exception $e) { 
return false; 
} 
} 
} 

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/194892-email-validation/
Share on other sites

The eregi functions are deprecated and you should consider using the preg functions instead. Have you actually tested your code with a valid e-mail? The reason I ask is your code appears to say if the e-mail matches an e-mail pattern return FALSE. Surely you wish to return false if the pattern is not matched?

Link to comment
https://forums.phpfreaks.com/topic/194892-email-validation/#findComment-1024714
Share on other sites

ok.. Now I am using this, but still, where ever I put it, is not validating...!!!

 

function checkEmail($email) {
// checks proper syntax
if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) {
  // gets domain name
  list($username,$domain)=split('@',$email);
  // checks for if MX records in the DNS
  if(!checkdnsrr($domain, 'MX')) {
   return false;
  }
  // attempts a socket connection to mail server
  if(!fsockopen($domain,25,$errno,$errstr,30)) {
   return false;
  }
  return true;
}
return false;
}

Link to comment
https://forums.phpfreaks.com/topic/194892-email-validation/#findComment-1024919
Share on other sites

Ok you are right about one thing... Since I entered the captcha session (which is working) The pasword check if empty, stopped. (Don't know why )The thing is, it doesn't give me an error if the email is wrong... is just accepts it. exept if the captcha session conflicts that also...

 

Here is my capthcha session just in case:

 

session_start();
   if($_SESSION['captchaCheck'] != $_POST['providedCaptcha'] && !empty($_SESSION['captchaCheck'])){
     // TODO
include 'register.php';
     echo "<center><font color=#FF0000>Οι χαρακτήρες που γράψατε (".$_POST['providedCaptcha'].") δεν είναι οι ίδιοι με τους αναπαραγώμενους (".$_SESSION['captchaCheck'].")!</font></center>";
     unset($_SESSION['captchaCheck']);
exit();
} 

Link to comment
https://forums.phpfreaks.com/topic/194892-email-validation/#findComment-1024927
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.