search
Homephp教程php手册PHP中如何实现常用邮箱的基本判断

在邮件发送出去之前,用户的基本信息已经存在于数据库中了,如果是个错误的邮箱或者是恶意多注册账户那就需要过滤了,下面为大家介绍下PHP中实现常用邮箱的判断

越来越多的网站希望用户使用邮箱进行注册,或者是绑定邮箱,这时候就要对邮箱的正确性进行确认,有的人采用发送邮件进行激活的方式来进行判断,从而激活一个账户,但是存在一个问题就是,在邮件发送出去之前,,用户的基本信息已经存在于数据库中了,如果是个错误的邮箱或者是恶意多注册账户,那就会造成非活动账号太多,占用数据库存储空间,这边就需要在之前就进行这些邮箱的过滤,因此作者写下下面的一个方法用来过滤邮箱。

复制代码 代码如下:


/**
* @todo 用户输入安全性检测
* @param $inputString 用户输入信息
* @return true/false
* @final 可以根据自己的需求进行过滤内容的变换
*/
public function checkUserInput($inputString){
if (strpos('script', $inputString)!=false){//检测是否含有script脚本
return FALSE;
}else if (strpos('iframe', $inputString)!=false){//检测是否含有iframe框架
return FALSE;
}else {
return TRUE;
}
}

/**
* @todo checkeemail
* @param emailString
* @return false/true
*/
public function checkEmail($emailString){
if ($this -> checkUserInput($emailString) === TRUE){//检测是否含有敏感词汇
if (strpos('@', $emailString) != FALSE){//检测是否存在@字符
$emailArr = explode('@', $emailString);
if (count($emailArr) > 2){//检测是否存在多个@字符
return FALSE;
}else{
if (in_array('@'.$emailArr[1], Yii::app() -> params['mail_suffix'])){//检测后缀是否满足日常常用邮箱后缀
return TRUE;
}else{
return FALSE;
}
}
}else{
return FALSE;
}
}else{
return FALSE;
}
}


其中我定义了一个常用邮箱的后缀的数组,具体如下:

//常用邮箱后缀,根据具体需求可以再增加

复制代码 代码如下:


'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',
),


到此邮箱的过滤方法就完成了,大家可以在此基础上进行进一步的完善!
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools