网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > PHP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.在 PHP 中用描点法“绘制”中文.
.基于PHP与XML的PDF文档生成技术.
.模仿OSO的论坛(四).
.投票管理程序.
.计数器详细设计.
.下载文件的点击数回填.
.php+oracle 分页类.
.PHP的开合式多级菜单程序.
.一个很简单的PHP的后端脚本,能够.
.我的论坛源代码(三).
.我的论坛源代码(七).
.聊天室php&mysql(四).
.PHP4实际应用经验篇(1).
.超级简单的发送邮件程序.
.PHP4实际应用经验篇(5).
.php,不用COM,生成excel文件.
.PHP网上调查系统.
.桌面中心(三) 修改数据库 &.
.用PHP和MYSQL建立计数器过程详解.
.桌面中心(一) 创建数据库 &.

全面測試email的有效性

发表日期:2000-12-18


一般我們常希望拜訪你的網站的朋友能留下Email  
但是很多人都會隨便打,造成管理員的困擾,  
以下這個class可以線上檢查Email是否是有效的Email(存不存在)  

<?  
class CEmail {  
var $email_regular_expression="^([a-z0-9_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,4}$";  
var $timeout=0;  
var $localhost="";  
var $localuser="";  

Function GetLine($connection)  
{  
for($line="";;)  
{  
if(feof($connection))  
return(0);  
$line.=fgets($connection,100);  
$length=strlen($line);  
if($length>=2  
&& substr($line,$length-2,2)=="rn")  
return(substr($line,0,$length-2));  
}  
}  

Function PutLine($connection,$line)  
{  
return(fputs($connection,"$linern"));  
}  

Function VerifyRule($email)  
{  
return(eregi($this->email_regular_expression,$email)!=0);  
}  

Function ValidateEmailHost($email,$hosts=0)  
{  
if(!$this->VerifyRule($email))  
return(0);  
$user=strtok($email,"@");  
$domain=strtok("");  
if(GetMXRR($domain,&$hosts,&$weights))  
{  
$mxhosts=array();  
for($host=0;$host<count($hosts);$host++)  
$mxhosts[$weights[$host]]=$hosts[$host];  
KSort($mxhosts);  
for(Reset($mxhosts),$host=0;$host<count($mxhosts);Next($mxhosts),$host++)  
$hosts[$host]=$mxhosts[Key($mxhosts)];  
}  
else  
{  
$hosts=array();  
if(strcmp(@gethostbyname($domain),$domain)!=0)  
$hosts[]=$domain;  
}  
return(count($hosts)!=0);  
}  

Function VerifyResultLines($connection,$code)  
{  
while(($line=$this->GetLine($connection)))  
{  
if(!strcmp(strtok($line," "),$code))  
return(1);  
if(strcmp(strtok($line,"-"),$code))  
return(0);  
}  
return(-1);  
}  

Function VerifyOnline($email)  
{  
if(!$this->ValidateEmailHost($email,&$hosts))  
return(0);  
if(!strcmp($localhost=$this->localhost,"")  
&& !strcmp($localhost=getenv("SERVER_NAME"),"")  
&& !strcmp($localhost=getenv("HOST"),""))  
$localhost="localhost";  
if(!strcmp($localuser=$this->localuser,"")  
&& !strcmp($localuser=getenv("USERNAME"),"")  
&& !strcmp($localuser=getenv("USER"),""))  
$localuser="root";  
for($host=0;$host<count($hosts);$host++)  
{  
if(($connection=($this->timeout ? fsockopen($hosts[$host],25,&$errno,&$error,$this->timeout) : fsockopen($hosts[$host],25))))  
{  
if($this->VerifyResultLines($connection,"220")>0  
&& $this->PutLine($connection,"HELO $localhost")  
&& $this->VerifyResultLines($connection,"250")>0  
&& $this->PutLine($connection,"MAIL FROM: <$localuser@$localhost>")  
&& $this->VerifyResultLines($connection,"250")>0  
&& $this->PutLine($connection,"RCPT TO: <$email>")  
&& ($result=$this->VerifyResultLines($connection,"250"))>=0)  
{  
fclose($connection);  
return($result);  
}  
fclose($connection);  
}  
}  
return(-1);  
}  

function Verify($email,$type=0) {  
    if($type==0) return $this->VerifyRule($email) ;  
    else     return $this->VerifyOnline($email) ;  

}  

};      
      
      
?>  


用法:  
$m=new CEmail;  
//僅檢查語法  
if($m->Verify("jerry@mail.jerry.com.tw",0)) echo "有效";  
else echo "無效";  

//線上檢查是否真的有該Email  
if($m->Verify("jerry@mail.jerry.com.tw",1)) echo "有效";  
else echo "無效";  
上一篇:怎样用PHP来给网页做导航栏 人气:11420
下一篇:下载文件的点击数回填 人气:11028
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐