checkdnsrr()

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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

checkdnsrr()

Post by hawleyjr »

I found the following code using the php function checkdnsrr()

http://us2.php.net/manual/en/function.checkdnsrr.php

I did a search on this site and only found a dozen or so questions about it which leads me to think not very many people use this function for such things as email validation.

Just out of curiosity, does anyone rely on this function or a similar function for email verification?

http://www.sitepoint.com/article/users- ... ddress-php

Code: Select all

// take a given email address and split it into the  
username and domain.
list($userName, $mailDomain) = split("@", $email);
if (checkdnsrr($mailDomain, "MX")) {
 // this is a valid email domain!
}
else {
 // this email domain doesn't exist! bad dog! no biscuit!
}
User avatar
Spaceboy
Forum Newbie
Posts: 3
Joined: Tue May 31, 2005 2:10 pm

Post by Spaceboy »

I have never used it, but it looks pretty useful, so I'm going to start.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

you might want to search at zend.com for a larger article ;)

and at phpclasses you can find a validator, which allows you to specify the specified level... (regular rexpression, mx record, ...)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Hmmm... something like this_isnt_a_real_email_address@hotmail.com would still be valid but it beats standard regex checking methods!

/me pops into snippets folder ;)
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

d11wtq wrote:Hmmm... something like this_isnt_a_real_email_address@hotmail.com would still be valid but it beats standard regex checking methods!

/me pops into snippets folder ;)
Gimme a week or two, and I'll have a link to the subversion repository entry for the regex we use for validating email addresses in the game project I'm working on.

Its opensource, and its RFC-compliant. I just haven't had time to commit the code yet. :)

And yes, that is a valid email address - so it does make it through regex. :)

The regex detects if it is *valid*, not if it is *active*. Active email addresses can only reliably be detected by sending an email and getting a response. All other tests (check user exists, knock, user info, etc) all have been used by spammers and are disabled by default in a non-trivial number of mail servers. (and thus, unreliable).

Of course, checking the domain name has a mx record is yet another issue..
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Roja wrote: Gimme a week or two, and I'll have a link to the subversion repository entry for the regex we use for validating email addresses in the game project I'm working on.
Sorry for the delay. Its up!

http://svn.gna.org/viewcvs/blacknova/tr ... iew=markup

Very simple. Pass it an RFC compliant email, and it returns true. Pass it bogus info, and it returns false.

Patches, comments, and rude limericks all welcome.
Post Reply