85 lines
2.1 KiB
PHP
Executable file
85 lines
2.1 KiB
PHP
Executable file
<?php
|
|
function email_check($email) {
|
|
$isValid=TRUE;
|
|
$atIndex = strrpos($email, "@");
|
|
if (is_bool($atIndex) && !$atIndex) {
|
|
$isValid = FALSE;
|
|
} else {
|
|
$domain = substr($email, $atIndex+1);
|
|
$local = substr($email, 0, $atIndex);
|
|
$localLen = strlen($local);
|
|
$domainLen = strlen($domain);
|
|
//user troppo lungo
|
|
if ($localLen < 1 || $localLen > 64) {
|
|
$isValid = FALSE;
|
|
//l'user incomincia o termina con un . o a 2 .. consecutivi
|
|
} elseif ($local[0] == '.' || $local[$localLen-1] == '.' || consecutive_dot($local)) {
|
|
$isValid = FALSE;
|
|
} elseif (! isValidDomain($domain)) {
|
|
$isValid = FALSE;
|
|
} elseif(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) {
|
|
// character not valid in local part unless
|
|
// local part is quoted
|
|
if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) {
|
|
$isValid = FALSE;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $isValid;
|
|
}
|
|
|
|
function isValidDomain($domain) {
|
|
$isValid=true;
|
|
$domainLen = strlen($domain);
|
|
|
|
if ($domainLen < 4 || $domainLen > 255) {
|
|
$isValid = FALSE;
|
|
//l'user incomincia o termina con un . o a 2 .. consecutivi
|
|
} elseif (consecutive_dot($domain) || $domain[0] == '.' || $domain[$domainLen-1] == '.' ) {
|
|
$isValid = FALSE;
|
|
} elseif (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
|
|
$isValid = FALSE;
|
|
//ha almeno un punto
|
|
} elseif (! strpos($domain, ".")) {
|
|
$isValid = FALSE;
|
|
} else {
|
|
//il dominio di primo livello è almeno 2 caratteri
|
|
$arr=explode(".", $domain);
|
|
if(strlen($arr[count($arr)-1])<2)
|
|
$isValid = FALSE;
|
|
}
|
|
|
|
return $isValid;
|
|
}
|
|
|
|
function consecutive_dot($string) {
|
|
$ret=false;
|
|
|
|
if(preg_match('/\\.\\./',$string))
|
|
$ret=true;
|
|
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* estrae dominio di secondo livello
|
|
*/
|
|
function dom($name){
|
|
$zon=explode(".",$name);
|
|
return implode(".",array_slice($zon,-3));
|
|
}
|
|
|
|
/* gets the data from a URL */
|
|
function get_data($url) {
|
|
$ch = curl_init();
|
|
$timeout = 5;
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
$data = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
return $data;
|
|
}
|
|
?>
|