|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我的这套线路可能跟许多学习PHP的爱好者不谋而合,这也算是一个循序渐进的学习过程,不过新手不要看到上面的概括就以为学习蛮简单的,默默在此不得不对您稍微泼一下冷水,任何东西其实都不简单。 普通我常但愿拜L你的W站的伴侣能留下Email
然而良多人都S便打,形成办理T的困_,
以下@class可以上z查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;
//Hz查Z法
if($m->Verify("jerry@mail.jerry.com.tw",0)) echo "无效";
else echo "o效";
//上z查是不是真的有Email
if($m->Verify("jerry@mail.jerry.com.tw",1)) echo "无效";
else echo "o效";
学习数据库了,MYSQL可算是PHP的黄金搭档了,不过,虽然话是这么说,你也可能恨不得把MYSQL给生吞活剥了,因为这一行一列的东东简直让自己头晕目眩。 |
|