How to implement basic judgment of common mailbox in PHP

  • 2020-12-07 03:59:07
  • OfStack

More and more websites want users to use email to register, or binding mailbox, this time is to confirm the correctness of the email, there are some people who are using email to activate the way to determine, so as to activate an account, but there's one problem is that, before send out, the basic information of the user already exists in the database, if is the wrong email or malicious registered accounts, that too much can cause the inactive accounts, take up the database storage space, side will need to be in before the mail filter, so the author wrote a method used to filter email below.
 
/** 
* @todo  User input security detection  
* @param $inputString  User input information  
* @return true/false 
* @final  You can filter content according to your own needs  
*/ 
public function checkUserInput($inputString){ 
if (strpos('script', $inputString)!=false){// Detect if there is any script The script  
return FALSE; 
}else if (strpos('iframe', $inputString)!=false){// Detect if there is any iframe The framework  
return FALSE; 
}else { 
return TRUE; 
} 
} 

/** 
* @todo checkeemail 
* @param emailString 
* @return false/true 
*/ 
public function checkEmail($emailString){ 
if ($this -> checkUserInput($emailString) === TRUE){// Check for sensitive words  
if (strpos('@', $emailString) != FALSE){// Detect the presence of @ character  
$emailArr = explode('@', $emailString); 
if (count($emailArr) > 2){// Detect if more than one exists @ character  
return FALSE; 
}else{ 
if (in_array('@'.$emailArr[1], Yii::app() -> params['mail_suffix'])){// Check whether the suffix satisfies the common mailbox suffix in daily use  
return TRUE; 
}else{ 
return FALSE; 
} 
} 
}else{ 
return FALSE; 
} 
}else{ 
return FALSE; 
} 
} 

Among them, I defined an array of suffixes for a commonly used mailbox, specifically as follows:

// Common mailbox suffixes can be added according to specific requirements
 
'mail_suffix'=>array('@hotmail.com', 
'@msn.com', 
'@yahoo.com', 
'@gmail.com', 
'@aim.com', 
'@aol.com', 
'@mail.com', 
'@walla.com', 
'@inbox.com', 
'@126.com', 
'@163.com', 
'@sina.com', 
'@21cn.com', 
'@sohu.com', 
'@yahoo.com.cn', 
'@tom.com', 
'@qq.com', 
'@etang.com', 
'@eyou.com', 
'@56.com', 
'@x.cn', 
'@chinaren.com', 
'@sogou.com', 
'@citiz.com', 
), 

Filter method to this mailbox is completed, we can progress on the basis of 1 step improvement!

Related articles: