diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..4f0611e --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Validate.php b/Validate.php new file mode 100644 index 0000000..7afa553 --- /dev/null +++ b/Validate.php @@ -0,0 +1,61 @@ + + * Date: 03.05.2016 + * Time: 21:28 + */ + +/** + * Class Validate. + */ +class Validate +{ + /** + * Static function for validating email addresses with multiple secure levels and blacklist. + * @param string $email email address + * @param int $level secure level + * @param array $lists filter lists like whitelist, blacklist, dnsbl,.. + * @return bool is the email address valid? + */ + static function email (string $email, int $level=1, array $lists=[]) : bool + { + $results = true; + $email = trim($email); // sanitize before validation + $split = explode('@', $email); + + // Whitelisted? + if(isset($lists['whitelist'])) { + if(in_array($email, $lists['whitelist'])) + return true; + } + + // Blacklisted? + if(isset($lists['blacklist'])) { + if(in_array($email, $lists['blacklist'])) + return false; + } + + // check format + if($results && $level >= 1) { + if(filter_var($email, FILTER_VALIDATE_EMAIL) === false) + { + $results = false; + } else { + $results = true; + } + } + + // check for dns MX entry + if($results && $level >= 2) { + $results = checkdnsrr($split[1], "MX"); + } + + // DNS Blacklist (domains) + if($results && isset($lists['dnsbl']) && $level >= 3) { + // TODO: check if domain is registered in dnsbl of list. + } + + return $results; + } +} \ No newline at end of file