Welcome Guest [Log In] [Register]
Add Reply
validate email domain name
Topic Started: Nov 17 2008, 10:06 AM (110 Views)
bustya
Member Avatar
The Master Bitchslapper
This function checks a registering member's submitted email address to see if it belongs to a real domain. This will NOT validate that the email account is real (use an activation key for that), but this will prevent users from submitting something like me@non-existent-site.com.




Add to database.php
Note: "$soandso" is undefined, it's just a placeholder
Code: HTML
 

function domain_exists($subemail,$record = 'MX')
{
list($soandso,$domain) = split('@',$subemail);
return checkdnsrr($domain,$record);
}



Overwrite in function register() in session.php
Code: HTML
 

/* Email error checking */
$field = "email"; //Use field name for email
if(!$subemail || strlen($subemail = trim($subemail)) == 0){
$form->setError($field, "not entered");
}
/* Check DNS to see if domain exists */
else if(!$database->domain_exists($subemail)){
$form->setError($field, "fake address");
}
else{
/* Check if valid email address */
$regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
."\.([a-z]{2,}){1}$";
if(!eregi($regex,$subemail)){
$form->setError($field, "invalid address");
}
$subemail = stripslashes($subemail);
}

Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Other · Next Topic »
Add Reply