SoFunction
Updated on 2025-03-10

Basic judgment on how to implement common mailboxes in PHP


/**
* @todo User input security detection
* @param $inputString User input information
* @return true/false
* @final can filter content transformation according to your needs
*/
public function checkUserInput($inputString){
if (strpos('script', $inputString)!=false){//Detection whether script script is included
return FALSE;
}else if (strpos('iframe', $inputString)!=false){//Detection whether it contains an iframe frame
return FALSE;
}else {
return TRUE;
}
}

/**
* @todo checkeemail
* @param emailString
* @return false/true
*/
public function checkEmail($emailString){
if ($this -> checkUserInput($emailString) === TRUE){//Check whether it contains sensitive words
if (strpos('@', $emailString) != FALSE){//Detection whether the @ character exists
$emailArr = explode('@', $emailString);
if (count($emailArr) > 2){//Detection whether there are multiple @ characters
return FALSE;
}else{
if (in_array('@'.$emailArr[1], Yii::app() -> params['mail_suffix'])){//Check whether the suffix meets the usual mailbox suffix
return TRUE;
}else{
return FALSE;
}
}
}else{
return FALSE;
}
}else{
return FALSE;
}
}