added email validation.
This commit is contained in:
parent
176ad1a681
commit
5d6a41ea85
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7" />
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* User: Marcel 'CoNfu5eD Naeve <confu5ed@serious-pro.de>
|
||||
* 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue