Ticket #599 (closed Patch: fixed)

Opened 7 months ago

Last modified 5 months ago

valid::email_domain error on win32

Reported by: Nowaker Owned by: Geert
Priority: minor Milestone: 2.2
Component: Helpers Version: SVN HEAD
Keywords: valid email_domain checkdnsrr Cc:

Description

Fatal error: Call to undefined function checkdnsrr() in E:\Dev\www\escapi2-shop\html\system\helpers\valid.php on line 58

PHP manual says:

This function is not implemented on Windows platforms.

Solution:

if(!function_exists('checkdnsrr'))
{
  function checkdnsrr($host, $type='')
  {
    if(!empty($host))
    {
      $type = (empty($type)) ? 'MX' :  $type;
      exec('nslookup -type='.$type.' '.escapeshellcmd($host), $result);
      $it = new ArrayIterator($result);
      foreach(new RegexIterator($it, '~^'.$host.'~', RegexIterator::GET_MATCH) as $result)
      {
        if($result)
        {
          return true;
        }                
      }
    }
    return false;
  }
}

Change History

  Changed 7 months ago by brettalton

Well that wouldn't work because what if I was in FreeBSD, Mac OS X or some other OS that supported PHP but does not have checkdnsrr()? I think if checkdnsrr() is not available, it should simply return false.

follow-up: ↓ 4   Changed 7 months ago by brettalton

That was a nice little copy and paste from the PHP documentation too:http://ca3.php.net/manual/en/function.checkdnsrr.php#82701

Please state that this is not your code next time.

  Changed 7 months ago by brettalton

http://ca3.php.net/manual/en/function.checkdnsrr.php#82701

Don't know what happened to the link above.

in reply to: ↑ 2 ; follow-up: ↓ 10   Changed 7 months ago by Nowaker

Replying to brettalton:

Well that wouldn't work because what if I was in FreeBSD, Mac OS X or some other OS that supported PHP but does not have checkdnsrr()? I think if checkdnsrr() is not available, it should simply return false.

The manual says that the function is not implemented on Win32s. They don't say anything about the BSDs and MACs, so they work (?). Maybe somebody try and inform us. (By the way, in your case - it should simply return TRUE, not FALSE. Returning FALSE would result in rejecting even good e-mails)

Replying to brettalton:

That was a nice little copy and paste from the PHP documentation too:http://ca3.php.net/manual/en/function.checkdnsrr.php#82701 Please state that this is not your code next time.

Yes, it is from the manual, as I have written "PHP manual says". But sorry that I didn't repeat it before the PHP code.

  Changed 7 months ago by brettalton

The only reason why I made a stink about 'where the code came from' is because I'm sure the Kohana developers would like to know the license on the code. If you post it here as your own, we assume we have rights to use it. If it's under the PHP documentation, we don't know the license.

I'm sure when you post on the PHP documentation page like that, you're releasing it as LGPL or something - and thus we can use it - but its always nice to know.

  Changed 7 months ago by Nowaker

  • owner changed from Shadowhand to - No owner -
  • component changed from Core to Helpers

Yes, I realise and that's why I said sorry.

  Changed 7 months ago by brettalton

Not a problem! I was just explaining why my comment may have came off negative, sorry.

  Changed 6 months ago by Shadowhand

  • version set to SVN HEAD
  • milestone changed from 2.1.2 to 2.2

Not sure how much I care, but I'm going to leave this open and move it to 2.2.

  Changed 6 months ago by Nowaker

In my opinion - we should care. There are people who develop applications on win32, the example is me. The solution is very simple. What do others think about fixing it?

in reply to: ↑ 4   Changed 5 months ago by Geert

  • keywords helper removed
  • owner changed from - No owner - to Geert
  • status changed from new to assigned

Replying to Nowaker:

The manual says that the function is not implemented on Win32s. They don't say anything about the BSDs and MACs, so they work (?). Maybe somebody try and inform us.

Not necessarily. What if PHP is running in safe mode? What if the checkdnsrr() function is added to the disable_functions setting? You cannot be sure that if that function is not available you are on Windows. That is also why I would not opt for a manual rewrite of the function.

(By the way, in your case - it should simply return TRUE, not FALSE. Returning FALSE would result in rejecting even good e-mails)

Agreed. If we can't prove domain does not exist, consider it valid until proven otherwise.

  Changed 5 months ago by Geert

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r2998. At least you won't get fatal errors anymore on Windows.

Note: See TracTickets for help on using tickets.