Re: QuickForm - E-Mail validation with checkdnsrr() - subdomains
| From: | Mark Steudel | Date: | Wed, 10 Feb 2010 20:17:22 +0000 |
| Subject: | Re: QuickForm - E-Mail validation with checkdnsrr() - subdomains | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-30274@lists.php.net to get a copy of this message | ||
Something else to try would be to test the subdomain with the
checkdnsrr function outside of that email function. Depending on how
DNS is setup, it's possible that the subdomain isn't actually an A
record but a CNAME and is therefore returning false. If you look at
the two checks, it only checks that it's a MX record or A record ...
Good Luck, Mark
On Wed, Feb 10, 2010 at 12:11 PM, James Collins <james@om4.com.au> wrote:
> Hi Markus,
>
> Which operating system are you running your PHP code from?
>
> According to http://php.net/manual/en/function.checkdnsrr.php,
> the function
> might not exist if you're using Windows.
>
> I do not have any specific experience with the checkEmail() or checkdnsrr()
> functions, but I have successfully used PEAR's NET_DNS package (
> http://pear.php.net/package/Net_DNS) for querying DNS records
> on both
> windows and linux servers.
>
> Regards,
>
> James Collins
>
>
>
> On 11 February 2010 00:47, Markus Ernst <derernst@gmx.ch> wrote:
>
>> Hello
>>
>> This is actually not specifically a QuickForm question, but it is related
>> to this function I took from the QuickForm manual, and which is actually
>> built-in natively in QuickForm, too:
>>
>> function checkEmail($email, $domainCheck = false)
>> {
>> if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
>> '\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
>> if ($domainCheck && function_exists('checkdnsrr')) {
>> list (, $domain) = explode('@', $email);
>> if (checkdnsrr($domain, 'MX') || checkdnsrr($domain,
>> 'A')) {
>> return true;
>> }
>> return false;
>> }
>> return true;
>> }
>> return false;
>> }
>>
>> Now it happend that the check for an e-mail address of the following form
>> returned false, although the address was claimed to be correct:
>>
>> firstname.lastname@subdomain.maindomain.tld
>>
>> So, both MX and A checks for subdomain.maindomain.tld returned false.
>> Performing the checks for maindomain.tld only, both returned true. So I
>> added a fix:
>>
>> function checkEmail($email, $domainCheck = false)
>> {
>> if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
>> '\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
>> if ($domainCheck && function_exists('checkdnsrr')) {
>> list (, $domain) = explode('@', $email);
>> if (checkdnsrr($domain, 'MX') || checkdnsrr($domain,
>> 'A')) {
>> return true;
>> }
>> // Fix: check with removed sub domains
>> $spl = explode(".", $domain);
>> $c = count($spl);
>> $domain = $spl[$c - 2] . "." . $spl[$c - 1];
>> if (checkdnsrr($domain, 'MX') || checkdnsrr($domain,
>> 'A')) {
>> return true;
>> }
>> return false;
>> }
>> return true;
>> }
>> return false;
>> }
>>
>> Now, I am not familiar with anything about MX and A records. Is this a
>> sensible fix, which should even make it into QuickForm(2)? Or is it rather
>> likely to introduce new problems I am not aware of? Thanks for your
>> comments.
>>
>> --
>> PEAR General Mailing List (http://pear.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
--
-----------------------------------------
Mark Steudel
P: 206.375.7244
msteudel@gmail.com
. : Work : .
http://www.mindfulinteractive.com
. : Play : .
http://www.steudel.org/blog