首页 > 资讯列表 > 编程/数据库 >> PHP

PHP+jQuery 注册模块的改进(二):邮箱激活

PHP 2014-12-10 01:03:57 转载来源: 网络整理/侵权必删

本文是PHP+jQuery 注册模块的改价的第二篇,主要是继续完善邮箱激活账号方面的功能,非常的详细,有需要的朋友可以参考下 接《PHP+jQuery 注册模块的改进之一》继续修改: ①在注册成功后返回登录邮件页面( maillogin.php ),在页面中用户可以点击链接跳转到自己注册邮箱的登录页面,可以再次发送激活链接; ②给激活链接设置有效期,过了有效期点击激活连接,会跳转页面让用户选择再次发送邮件或者返回注册页;再次发送邮件后,进邮箱点击链接激活; ③点击重新发送激活连接,不跳转页面,在当前页无刷新弹出通知:已重新发送链接,几秒钟之后通知消失; ④点击更换收件邮箱,跳转至注册页 1.点击邮箱链接跳转至相应邮箱登陆界面 思路: 在maillogin.js中( 也可在php中设置 )设置常用邮件地址列表,当用户的注册邮箱和列表中的邮箱匹配时,则显示button"立即登录验证邮箱",点击则跳转至邮箱的登陆首页;如果用户注册的邮箱在列表中不存在时,则不显示登陆button。 如图,当邮箱列表中存在注册邮箱时:

本文是PHP+jQuery 注册模块的改价的第二篇,主要是继续完善邮箱激活账号方面的功能,非常的详细,有需要的朋友可以参考下

接《PHP+jQuery 注册模块的改进之一》继续修改:

①在注册成功后返回登录邮件页面( maillogin.php ),在页面中用户可以点击链接跳转到自己注册邮箱的登录页面,可以再次发送激活链接;

②给激活链接设置有效期,过了有效期点击激活连接,会跳转页面让用户选择再次发送邮件或者返回注册页;再次发送邮件后,进邮箱点击链接激活;

③点击重新发送激活连接,不跳转页面,在当前页无刷新弹出通知:已重新发送链接,几秒钟之后通知消失;

④点击更换收件邮箱,跳转至注册页

1.点击邮箱链接跳转至相应邮箱登陆界面

思路:

在maillogin.js中( 也可在php中设置 )设置常用邮件地址列表,当用户的注册邮箱和列表中的邮箱匹配时,则显示button"立即登录验证邮箱",点击则跳转至邮箱的登陆首页;如果用户注册的邮箱在列表中不存在时,则不显示登陆button。

如图,当邮箱列表中存在注册邮箱时:

当邮箱列表中不存在注册邮箱时:

当传递的参数不是有效的邮箱时提示参数错误:

maillogin.php:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>注册页面</title>
<link href="templets/css/common.css" rel="stylesheet" type="text/css">
<style>
#container{ 

  background-color:#fff;
  width:990px;
  height:547px;
  margin-top:50px;
  margin-bottom:20px;
  overflow:hidden;
}
#mailChk{ width:530px; margin:100px auto auto auto; position:relative;}

.mailfonts{ margin-left:20px;}
.mailpic{ float:left;}
.mailfonts{ float:left;}
.hfonts{ font-size:22px; }
.ftit{ 
  
  position:relative; 
  top:-70px; 
  left:-180px; 
  border-bottom:1px solid #eee;
  width:870px;
  padding-bottom:10px;
  font-size: 20px;
  font-weight: normal;
  font-family: "Microsoft YaHei",5fae8f6f96c59ed1,arial,5b8b4f53;
  color: #323232;
}
.ftit2{

  height:1px;
  top:50px; 
  left:-180px; 
}
.sfonts{ line-height:48px; color:#666;}
.orange{ color:#ee8c18;}
#maillogin{

  display: block;
  width: 390px;
  height: 50px;
  line-height: 50px;
  border: 0;
  overflow: hidden;
  text-align: center;
  background: #69b3f2;
  font-family: "Microsoft YaHei",5fae8f6f96c59ed1,arial,5b8b4f53;
  font-size: 26px;
  -webkit-border-radius: 2px;
  -moz-border-radius: 2px;
  border-radius: 2px;
  margin:100px auto 0 85px;
  cursor:pointer;
}

#maillogin:hover{ background: #7cbdf5;}
#maillogin,#maillogin:hover{ color:#fff;}
#maillogin a{ color:#fff;}

.notice{ 
  
  position:relative;
  bottom:-70px;
  left:-180px;
}
.notit{ font-size:14px; color:#949494; font-weight:bold; font-family:arial;}
.noul{ color:#949494; margin-left:-40px;}
</style>
<script src="templets/js/jquery-1.8.3.min.js"></script>
<script src="templets/js/maillogin.js"></script>
</head>

<body>

<!--顶部长条-->
<div id="header-nav">
  <div id="header-nav-fonts">
    <span class="top-tie-big"><a href="#">Dee's BLOG</a></span> 
    <span class="top-tie"> | </span>
    <span class="top-tie-big">注册</span>
    <span class="top-tie-small">已有帐号?马上<a href="#">登录</a></span>
    <div class="cls"></div>
  </div>
</div>

<!-- 内容区 -->
<div id="container">

  <div id="mailChk">
    <?php 
  
      if(isset($_GET['m']) && $_GET['m']!=""){
      
        $m = $_GET['m'];
      }else{
      
        echo "<div class="hfonts ftit">操作有误,<a href="templets/register.html">请重新注册</div>";
        exit();
      }
    ?>
    <div class="hfonts ftit">邮箱验证</div>
    <img class="mailpic" src="templets/images/mail.jpg">
    <div class="mailfonts">
      <div class="hfonts">验证邮件已发出,请48小时内登陆邮箱验证</div>
      <div class="sfonts">登录邮箱 <a id="mailaddr" class="orange"><?php echo $m;?></a> ,并按邮件提示操作即可</div>
    </div>
    <button type="button" id="maillogin"><a href="">立即登录邮箱验证</a></button>
    <div class="ftit ftit2"></div>
    <div class="cls"></div>
    <div class="notice">
      <h3 class="notit">还没有收到验证邮件呢?</h3>
      <ul class="noul">
        <li>1.尝试到广告邮件、垃圾邮件目录里找找看</li>
        <li>2.<a class="blue" href="#">再次发送验证邮件</a></li>
        <li>3.如果重发注册验证邮件仍然没有收到,请更换<a class="blue" href="#">另一个邮件地址</a></li>
      </ul>
    </div>
  </div>
  
</div>
</body>
</html>

maillogin.js:

本文是PHP+jQuery 注册模块的改价的第二篇,主要是继续完善邮箱激活账号方面的功能,非常的详细,有需要的朋友可以参考下

$(function(){    //邮箱地址  function mailaddr(mail){              if(!mail.split("@")[1]){          alert("参数错误");      return false;    }    var mail = mail.split("@");        mail = mail[1].toLowerCase();        //与常用邮箱进行对比    if(mail == "qq.com" || mail == "vip.qq.com" || mail == "foxmail.com"){          return 'mail.qq.com';    }else if(mail == '163.com'){      return 'mail.163.com';    }else if(mail == 'vip.163.com'){            return 'vip.163.com';    }else if(mail == '126.com'){      return'mail.126.com';    }else if(mail == 'gmail.com'){      return'mail.google.com';    }else if(mail == 'sohu.com'){      return'mail.sohu.com';    }else if(mail == 'tom.com'){      return'mail.tom.com';    }else if(mail == 'vip.sina.com'){      return'vip.sina.com';    }else if(mail == 'sina.com.cn' || mail == 'sina.com'){      return'mail.sina.com.cn';    }else if(mail == 'tom.com'){      return'mail.tom.com';    }else if(mail == 'yahoo.com.cn' || mail == 'yahoo.cn'){      return'mail.cn.yahoo.com';    }else if(mail == 'tom.com'){      return'mail.tom.com';    }else if(mail == 'yeah.net'){      return'www.yeah.net';    }else if(mail == '21cn.com'){      return'mail.21cn.com';    }else if(mail == 'hotmail.com'){      return'www.hotmail.com';    }else if(mail == 'sogou.com'){      return'mail.sogou.com';    }else if(mail == '188.com'){      return'www.188.com';    }else if(mail == '139.com'){      return'mail.10086.cn';    }else if(mail == '189.cn'){      return'webmail15.189.cn/webmail';    }else if(mail == 'wo.com.cn'){      return'mail.wo.com.cn/smsmail';    }else if(mail == '139.com'){      return'mail.10086.cn';    }else{            return'';    }      }  var uemailaddr = $("#mailaddr").text();    if(mailaddr(uemailaddr) == ""){      $("#maillogin").remove();    //控制样式    $(".ftit2").css("top","110px");    $(".notice").css("bottom","-120px");    $("#mailaddr").click(function(){          return false;    });  }else{      $("#mailaddr").attr("href","http://"+mailaddr(uemailaddr));    $("#maillogin a").attr("href","http://"+mailaddr(uemailaddr));  }})

2.给激活链接设置失效时间

关于设置失效时间的目的,我在网上看到有这几种说法,第一是节省资源,过期的数据会被清除,这种说法我不认同,因为在过期之后,只是这一条激活连接不能使用,但是注册用户可以重新发送链接,所以用户数据并没有被清除;第二种说法是安全,即在较短时间内激活,可以避免用户邮箱被盗引发的安全问题,对于这一点我也不认同,因为即使用户邮箱被盗,还是可以重新发送激活链接,激活链接的地址仍然是在邮箱里面,所以和被盗不被盗没有关系;我认为是,在一个较长的时间内,如果网站的注册机制或者找回密码机制发生了变化,失效时间可以在一定程度上避免很早之前的激活链接仍按照以前的机制而带来激活错误或者找回密码错误,此时用户可以选择重新生成最新的激活链接来保证注册或者找回密码的正确性,对网站来说更稳定安全。

思路:

需要在数据库中增加两个字段,分别是表示用户的注册日期:regdate( int ),和激活链接是否有效的lockurl( tinyint )。

当用户注册成功时,把当前日期插入到表中的regdate字段;当用户超过有效期没有点击激活链接,再次点击激活链接时就把数据库中的lock字段修改成1,当lock为1时,该链接失效,直到用户重新生成注册链接时更换activekey后,把lock值设为0,同时更新注册时间,用户才可以点击新的链接发送邮件进行激活。

修改和新增的的文件有:

register_chk.php,注册成功时把当前的时间戳插入表中;

activation.php中在update user表的active字段之前,先判断是否超过有效期,如果超过,则active字段不变,同时lockurl字段设为1,此时给出提示:请重新激活并且跳转至reactivation.php页面;

reactivation.php接受参数,如果参数正确,则显示是重新收取激活链接还是返回注册页,如果参数错误则直接返回注册页;

当选择重新收取激活链接,则跳转至remail.php,如果参数正确,则更新注册时间和activekey,然后重新发送邮件,邮件中的地址依然指向activation.php。如果参数错误,则跳转回注册页。

其他修改之处:

1.把邮件代码写成邮件类

邮件注册类mail.class.php:

<?php function postmail($auth,$port,$envelope,$password,$smtp,$postuemail,$subject,$mailbody){  //$smtp smtp邮件服务器地址  //$postuemail 用户注册邮件  //$subject 邮件主题  //$mailbody 邮件内容   $config = array(        'auth'=>$auth,//发件人    'port' =>$port,//端口    'username'=>$envelope,//发件邮箱    'password'=>$password //发件邮箱密码    );    //实例化验证的对象,使用gmail smtp服务器  $transport = new Zend_Mail_Transport_Smtp($smtp,$config);  $mail = new Zend_Mail('utf-8');    $mail->addTo($postuemail,'获取用户注册激活链接');  $mail->setFrom($envelope,$auth);  $mail->setSubject($subject);  $mail->setBodyHtml($mailbody);  $mail->send($transport);}

2.用户名注册时区分大小写,修改checkname.php

//用户名区分大小写$sql = "select uname from user where binary uname='".$uname."'";

流程图:

需要注意的是,GET传递的参数也要进行转义处理。

Js倒计时跳转代码 showTime.js:

var textBox = document.getElementById("textBox");var second = document.getElementById("second");var t = 4;function showTime(href){  t-=1;  second.innerHTML = t;  if(t==0){      textBox.innerHTML = "正在跳转...";    self.location = href;  }  setTimeout("showTime(href)",1000);}

注册并发送邮件代码 register_chk.php:

<?php   header("charst=utf-8");  include_once 'conn/conn.php';  include_once 'Zend/Mail/Transport/Smtp.php';  include_once 'Zend/Mail.php';  include_once 'mail.class.php';    //激活key,生成的随机数  $key = md5(rand());    //先写入数据库,再发邮件  //写入数据库  //判断是否开启magic_quotes_gpc  if(get_magic_quotes_gpc()){      $postuname = $_POST['uname'];    $postupwd = $_POST['upwd'];    $postuemail = $_POST['uemail'];  }else{        $postuname = addslashes($_POST['uname']);    $postupwd = addslashes($_POST['upwd']);    $postuemail = addslashes($_POST['uemail']);  }  function check_input($value){      // 如果不是数字则加引号    if (!is_numeric($value)){          $value = mysql_real_escape_string($value);    }    return $value;  }    $postuname = check_input($postuname);  $postupwd = check_input($postupwd);  $postuemail = check_input($postuemail);  $sql = "insert into user(uname,upwd,uemail,activekey,regdate)values('".trim($postuname)."','".md5(trim($postupwd))."','".trim($postuemail)."','".$key."','".time()."')";  $num = $conne->uidRst($sql);  if($num == 1){        //插入成功时发送邮件    //用户激活链接    $url = 'http://'.$_SERVER['HTTP_HOST'].'/activation.php';    //urlencode函数转换url中的中文编码    //带反斜杠    $url.= '?name='.urlencode(trim($postuname)).'&k='.$key;//file_put_contents("D:/mylog.log",$url." *********rn",FILE_APPEND);    //定义登录使用的邮箱    $envelope = '[email protected]';    $password = '换成邮箱的密码';    $port = 25;    $auth = 'login';    $smtp = 'smtp.126.com';        //激活邮件的主题和正文    $subject = '激活您的帐号';    $mailbody = '注册成功,<a href="'.$url.'" target="_blank">请点击此处激活帐号</a>';        postmail($auth,$port,$envelope,$password,$smtp,$postuemail,$subject,$mailbody);    echo "<script>self.location="maillogin.php?m=".$postuemail."";</script>";  }else{      //提示激活失败并跳转    echo "<div id="textBox">激活失败,请重新注册,<span id="second"></span> 秒钟后跳转至重新激活页...</div>";    echo "<script src="templets/js/showTime.js"></script>";          echo "<script>var href='register.php';showTime(href);</script>";  }?>

激活。activation.php:

<?php session_start();header('Content-type:text/html;charset=utf-8');include_once 'conn/conn.php';$nowTime = time();$table = "user";if(!empty($_GET['name']) && !is_null($_GET['name']) && !empty($_GET['k']) && !is_null($_GET['k'])){            if(get_magic_quotes_gpc()){      $getname = stripslashes(urldecode($_GET['name']));    $k = stripslashes(urldecode($_GET['k']));  }else{      $getname = urldecode($_GET['name']);    $k = urldecode($_GET['k']);  }  //urldecode反转url中的中文编码  $sql = "select * from ".$table." where uname='".$getname."' and activekey='".$k."'";file_put_contents("D:/mylog.log",$sql."  ---rn",FILE_APPEND);  $num = $conne->getRowsNum($sql);  if($num>0){        $rs = $conne->getRowsRst($sql);      //注册时间    $rsRegdate = $rs['regdate'];        //有效期2分钟    if($nowTime > $rsRegdate+120){          //超过有效期      $upnum = $conne->uidRst("update ".$table." set lockurl = 1 where uname = '".$getname."' and activekey = '".$k."'");      if($upnum>0){        //提示激活失败并跳转        echo "<div id="textBox">超过激活有效期,激活失败,<span id="second"></span> 秒钟后跳转至重新激活页...</div>";        echo "<script src="templets/js/showTime.js"></script>";        echo "<script>var href='reactivation.php?n=".urlencode($getname)."&k=".$k."';showTime(href);</script>";      }else{              //提示激活失败并跳转        echo "<div id="textBox">激活失败,请重新注册,<span id="second"></span> 秒钟后跳转至重新激活页...</div>";        echo "<script src="templets/js/showTime.js"></script>";              echo "<script>var href='register.php';showTime(href);</script>";      }    }else{          $upnum = $conne->uidRst("update ".$table." set active = 1 where uname = '".$getname."' and activekey = '".$k."'");      if($upnum>0){              $_SESSION['name'] = urldecode($getname);        echo "<script>alert('您已成功激活');window.location.href='main.php';</script>";      }else{              echo "<script>alert('您已经激活过了');window.location.href='main.php';</script>";      }    }        }else{        //提示激活失败并跳转    echo "激活链接已失效,请重新发送激活链接或重新注册";    echo "<script>window.setTimeout("self.location='register.php'",3000);</script>";  }}?>

用户选择重新激活或返回注册页 reactivation.php:

<?phpheader("charst=utf-8");if(isset($_GET['n']) && $_GET['n']!="" && isset($_GET['k']) && $_GET['k']!=""){  //过滤处理  if(get_magic_quotes_gpc()){      $n = stripslashes(urldecode($_GET['n']));    $k = stripslashes(urldecode($_GET['k']));  }else{    $n = $_GET['n'];    $k = $_GET['k'];  }  echo "<a href='remail.php?n=".urlencode($n)."&k=".urlencode($k)."'>重新收取激活邮件</a>";  echo "<a href='register.php'>返回注册页</a>";}else{  echo "<div id="textBox">参数错误,请重新注册,<span id="second"></span> 秒钟后跳转至注册页...</div>";  echo "<script src="templets/js/showTime.js"></script>";        echo "<script>var href='register.php';showTime(href);</script>";}?>

重新发送邮件 remail.php:

<?phpheader("charst=utf-8");include_once 'conn/conn.php';include_once 'Zend/Mail/Transport/Smtp.php';include_once 'Zend/Mail.php';include_once 'mail.class.php';if(isset($_GET['n']) && $_GET['n']!="" && isset($_GET['k']) && $_GET['k']!=""){  //过滤处理  if(get_magic_quotes_gpc()){      $n = stripslashes(urldecode($_GET['n']));    $k = stripslashes(urldecode($_GET['k']));  }else{    $n = $_GET['n'];    $k = $_GET['k'];  }    $table = "user";  //先查询记录  $sql = "select * from ".$table." where uname='".$n."' and activekey='".$k."'";  $rs = $conne->getRowsRst($sql);    $rsuemail = $rs['uemail'];  $num = $conne->getRowsNum($sql);  if($num == 1){      $key = md5(rand());    //更新注册时间    $nowTime = time();    //update activekey和lockurl    $upnum = $conne->uidRst("update ".$table." set activekey = '".$key."' , lockurl=0,regdate = '".$nowTime."' where uname = '".$n."' and activekey = '".$k."'");    if($upnum == 1){          //插入成功时发送邮件      //用户激活链接      $url = 'http://'.$_SERVER['HTTP_HOST'].'/activation.php';      //urlencode函数转换url中的中文编码      //带反斜杠      $url.= '?name='.urlencode((trim($n))).'&k='.$key;      //定义登录使用的邮箱      $envelope = '[email protected]';      $password = '换成自己的邮箱密码';      $port = 25;      $auth = 'login';      $smtp = 'smtp.126.com';            //激活邮件的主题和正文      $subject = '激活您的帐号';      $mailbody = '注册成功,<a href="'.$url.'" target="_blank">请点击此处激活帐号</a>';      postmail($auth,$port,$envelope,$password,$smtp,$rsuemail,$subject,$mailbody);      echo "<script>self.location="maillogin.php?m=".$rsuemail."";</script>";          }else{          //提示激活失败并跳转      echo "<div id="textBox">激活失败,<span id="second"></span> 秒钟后跳转至注册页...</div>";      echo "<script src="templets/js/showTime.js"></script>";            echo "<script>var href='register.php';showTime(href);</script>";    }      }else{      //提示激活失败并跳转    echo "<div id="textBox">12激活失败,<span id="second"></span> 秒钟后跳转至注册页...</div>";    echo "<script src="templets/js/showTime.js"></script>";          echo "<script>var href='register.php';showTime(href);</script>";  }}else{  echo "<div id="textBox">参数错误,请重新注册,<span id="second"></span> 秒钟后跳转至注册页...</div>";  echo "<script src="templets/js/showTime.js"></script>";        echo "<script>var href='register.php';showTime(href);</script>";}?>

3.maillogin.php页面重新发送激活链接

思路: 注册页register_chk.php和重新发送邮件的remail.php页面在发送邮件以后跳至maillogin.php时,除了把email通过GET传递过去,再加上name和key,在maillogin.php页面把接受到的后两个参数接受到hidden的input里,通过jQuery的post方法请求remailajax.php重新发送邮件。发送成功以后通过jQuery设置定时器显示文字通知用户,4秒后自动消失。

如图:

代码:

register_chk.php:

<?php   header("charst=utf-8");  include_once 'conn/conn.php';  include_once 'Zend/Mail/Transport/Smtp.php';  include_once 'Zend/Mail.php';  include_once 'mail.class.php';    //激活key,生成的随机数  $key = md5(rand());    //先写入数据库,再发邮件  //写入数据库  //判断是否开启magic_quotes_gpc  if(get_magic_quotes_gpc()){      $postuname = trim($_POST['uname']);    $postupwd = trim($_POST['upwd']);    $postuemail = trim($_POST['uemail']);  }else{        $postuname = addslashes(trim($_POST['uname']));    $postupwd = addslashes(trim($_POST['upwd']));    $postuemail = addslashes(trim($_POST['uemail']));  }  function check_input($value){      // 如果不是数字则加引号    if (!is_numeric($value)){          $value = mysql_real_escape_string($value);    }    return $value;  }    $postuname = check_input($postuname);  $postupwd = check_input($postupwd);  $postuemail = check_input($postuemail);  $sql = "insert into user(uname,upwd,uemail,activekey,regdate)values('".$postuname."','".md5($postupwd)."','".$postuemail."','".$key."','".time()."')";  $num = $conne->uidRst($sql);  if($num == 1){        //插入成功时发送邮件    //用户激活链接    $url = 'http://'.$_SERVER['HTTP_HOST'].'/activation.php';    //urlencode函数转换url中的中文编码    //带反斜杠    $url.= '?name='.urlencode($postuname).'&k='.$key;    //定义登录使用的邮箱    $envelope = '[email protected]';    $password = '邮箱密码';    $port = 25;    $auth = 'login';    $smtp = 'smtp.126.com';        //激活邮件的主题和正文    $subject = '激活您的帐号';    $mailbody = '注册成功,<a href="'.$url.'" target="_blank">请点击此处激活帐号</a>';        postmail($auth,$port,$envelope,$password,$smtp,$postuemail,$subject,$mailbody);    echo "<script>self.location="maillogin.php?m=".$postuemail."&n=".urlencode($postuname)."&k=".$key."";</script>";  }else{      //提示激活失败并跳转    echo "<div id="textBox">激活失败,请重新注册,<span id="second"></span> 秒钟后跳转至重新激活页...</div>";    echo "<script src="templets/js/showTime.js"></script>";          echo "<script>var href='register.php';showTime(href);</script>";  }?>

remail.php:

<?phpheader("charst=utf-8");include_once 'conn/conn.php';include_once 'Zend/Mail/Transport/Smtp.php';include_once 'Zend/Mail.php';include_once 'mail.class.php';if(isset($_GET['n']) && $_GET['n']!="" && isset($_GET['k']) && $_GET['k']!=""){  //过滤处理  if(get_magic_quotes_gpc()){      $n = stripslashes(urldecode($_GET['n']));    $k = stripslashes(urldecode($_GET['k']));  }else{    $n = $_GET['n'];    $k = $_GET['k'];  }file_put_contents("D:/mylog.log",$n."  xxxrn",FILE_APPEND);    $table = "user";  //先查询记录  //addslashes($n) 因为使用了mysql_real_escape_string,所以存储在数据库中的是带转义的字符串  $sql = "select * from ".$table." where uname='".$n."' and activekey='".$k."'";  $rs = $conne->getRowsRst($sql);    $rsuemail = $rs['uemail'];file_put_contents("D:/mylog.log",$sql." xxxrn",FILE_APPEND);  $num = $conne->getRowsNum($sql);  if($num == 1){      $key = md5(rand());    //更新注册时间    $nowTime = time();    //update activekey和lockurl    $upnum = $conne->uidRst("update ".$table." set activekey = '".$key."' , lockurl=0,regdate = '".$nowTime."' where uname = '".$n."' and activekey = '".$k."'");    if($upnum == 1){          //插入成功时发送邮件      //用户激活链接      $url = 'http://'.$_SERVER['HTTP_HOST'].'/activation.php';      //urlencode函数转换url中的中文编码      //带反斜杠      $url.= '?name='.urlencode((trim($n))).'&k='.$key;      //定义登录使用的邮箱      $envelope = '[email protected]';      $password = '邮箱密码';      $port = 25;      $auth = 'login';      $smtp = 'smtp.126.com';            //激活邮件的主题和正文      $subject = '激活您的帐号';      $mailbody = '注册成功,<a href="'.$url.'" target="_blank">请点击此处激活帐号</a>';      postmail($auth,$port,$envelope,$password,$smtp,$rsuemail,$subject,$mailbody);      echo "<script>self.location="maillogin.php?m=".$rsuemail."&n=".urlencode($n)."&k=".$key."";</script>";    }else{          //提示激活失败并跳转      echo "<div id="textBox">22激活失败,<span id="second"></span> 秒钟后跳转至注册页...</div>";      echo "<script src="templets/js/showTime.js"></script>";            echo "<script>var href='register.php';showTime(href);</script>";    }      }else{      //提示激活失败并跳转    echo "<div id="textBox">12激活失败,<span id="second"></span> 秒钟后跳转至注册页...</div>";    echo "<script src="templets/js/showTime.js"></script>";          echo "<script>var href='register.php';showTime(href);</script>";  }}else{  echo "<div id="textBox">参数错误,请重新注册,<span id="second"></span> 秒钟后跳转至注册页...</div>";  echo "<script src="templets/js/showTime.js"></script>";        echo "<script>var href='register.php';showTime(href);</script>";}?>

maillogin.php:

<!DOCTYPE html><html><head><meta charset="utf-8"><title>注册页面</title><link href="templets/css/common.css" rel="stylesheet" type="text/css"><style>#container{   background-color:#fff;  width:990px;  height:547px;  margin-top:50px;  margin-bottom:20px;  overflow:hidden;}#mailChk{ width:530px; margin:100px auto auto auto; position:relative;}.mailfonts{ margin-left:20px;}.mailpic{ float:left;}.mailfonts{ float:left;}.hfonts{ font-size:22px; }.ftit{     position:relative;   top:-70px;   left:-180px;   border-bottom:1px solid #eee;  width:870px;  padding-bottom:10px;  font-size: 20px;  font-weight: normal;  font-family: "Microsoft YaHei",5fae8f6f96c59ed1,arial,5b8b4f53;  color: #323232;}.ftit2{  height:1px;  top:50px;   left:-180px; }.sfonts{ line-height:48px; color:#666;}.orange{ color:#ee8c18;}#maillogin{  display: block;  width: 390px;  height: 50px;  line-height: 50px;  border: 0;  overflow: hidden;  text-align: center;  background: #69b3f2;  font-family: "Microsoft YaHei",5fae8f6f96c59ed1,arial,5b8b4f53;  font-size: 26px;  -webkit-border-radius: 2px;  -moz-border-radius: 2px;  border-radius: 2px;  margin:100px auto 0 85px;  cursor:pointer;}#maillogin:hover{ background: #7cbdf5;}#maillogin,#maillogin:hover{ color:#fff;}#maillogin a{ color:#fff;}.notice{     position:relative;  bottom:-70px;  left:-180px;}#notice{  width:300px;  height:200px;  position:fixed;  top:50%;  left:50%;  margin:-100px 0 0 -150px;  background:#eee;  text-align:center;  line-height:180px;  display:none;}.notit{ font-size:14px; color:#949494; font-weight:bold; font-family:arial;}.noul{ color:#949494; margin-left:-40px;}</style><script src="templets/js/jquery-1.8.3.min.js"></script><script src="templets/js/maillogin.js"></script></head><body><!--顶部长条--><div id="header-nav">  <div id="header-nav-fonts">    <span class="top-tie-big"><a href="#">Dee's BLOG</a></span>     <span class="top-tie"> | </span>    <span class="top-tie-big">注册</span>    <span class="top-tie-small">已有帐号?马上<a href="#">登录</a></span>    <div class="cls"></div>  </div></div><!-- 内容区 --><div id="container">  <div id="mailChk">    <?php         if(isset($_GET['m']) && $_GET['m']!=""){              $m = $_GET['m'];      }else{              echo "<div class="hfonts ftit">操作有误,<a href="templets/register.html">请重新注册</div>";        exit();      }      //接收用户名和key      if(!empty($_GET['n']) && !is_null($_GET['n']) && !empty($_GET['k']) && !is_null($_GET['k'])){                  if(get_magic_quotes_gpc()){            $n = stripslashes(urldecode($_GET['n']));          $k = stripslashes(urldecode($_GET['k']));        }else{            $n = urldecode($_GET['n']);          $k = urldecode($_GET['k']);        }      }      require_once 'mail.class.php';    ?>    <div class="hfonts ftit">邮箱验证</div>    <img class="mailpic" src="templets/images/mail.jpg">    <div class="mailfonts">      <div class="hfonts">验证邮件已发出,请48小时内登陆邮箱验证</div>      <div class="sfonts">登录邮箱 <a id="mailaddr" class="orange"><?php echo $m;?></a> ,并按邮件提示操作即可</div>      <input id="n" type="hidden" value="<?php echo $n;?>"/>      <input id="k" type="hidden" value="<?php echo $k;?>"/>    </div>    <button type="button" id="maillogin"><a href="">立即登录邮箱验证</a></button>    <div class="ftit ftit2"></div>    <div class="cls"></div>    <div class="notice">      <h3 class="notit">还没有收到验证邮件呢?</h3>      <ul class="noul">        <li>1.尝试到广告邮件、垃圾邮件目录里找找看</li>        <li>2.<a id="re" class="blue" href="#">再次发送验证邮件</a></li>        <li>3.如果重发注册验证邮件仍然没有收到,请更换<a class="blue" href="register.php">另一个邮件地址</a></li>      </ul>    </div>  </div>  </div></body><script>  $(function(){    $("#re").click(function(){          $.post("remailajax.php",{                    //要传递的数据       n : $("#n").val(),       k : $("#k").val(),       m : $("#mailaddr").text()      },function(data,textStatus){        if(data == 0){                success();        }else{                alert("重新发送邮件失败");        }      });      return false;    });        $notice = $("<div id="notice">邮件已经发送,请到邮箱中查看...</div>");    function success(){            $notice.insertAfter($("#mailChk"));      $notice.show(300);    }              function hide(){          if($notice){              $notice.hide(300);      }    }    //显示4秒    setInterval(hide,4000);  });</script></html>

emailajax.php:

<?phpheader("charset=utf-8");include_once 'Zend/Mail/Transport/Smtp.php';include_once 'Zend/Mail.php';require_once 'mail.class.php';if(isset($_POST['n']) && $_POST['n']!="" && isset($_POST['k']) && $_POST['k']!="" && isset($_POST['m']) && $_POST['m']!=""){  if(get_magic_quotes_gpc()){      $n = stripslashes(urldecode($_POST['n']));    $k = stripslashes(urldecode($_POST['k']));    $m = stripslashes(urldecode($_POST['m']));  }else{    $n = $_POST['n'];    $k = $_POST['k'];    $m = $_POST['m'];  }    $url = 'http://'.$_SERVER['HTTP_HOST'].'/activation.php';  //urlencode函数转换url中的中文编码  //带反斜杠  $url.= '?name='.urlencode($n).'&k='.$k;  //定义登录使用的邮箱  $envelope = '[email protected]';  $password = '邮箱密码';  $port = 25;  $auth = 'login';  $smtp = 'smtp.126.com';    //激活邮件的主题和正文  $subject = '激活您的帐号';  $mailbody = '注册成功,<a href="'.$url.'" target="_blank">请点击此处激活帐号</a>';  postmail($auth,$port,$envelope,$password,$smtp,$m,$subject,$mailbody);  echo 0;}

4.更换邮箱即重新注册。

maillogin.php代码片段:

<li>3.如果重发注册验证邮件仍然没有收到,请更换<a class="blue" href="register.php">另一个邮件地址</a></li>

 

5.此时目录结构和数据库

ROOT:
├─conn
│ ├─conn.php

├─templets
│ ├─css
│ │ ├─common.css
│ │ ├─register.css
│ │
│ ├─images
│ │
│ └─js
│ ├─jquery-1.8.3.min.js
│ ├─register.js
│ ├─emailup.js
│ ├─showTime.js
│ ├─maillogin.js

├─chkname.php
├─chkemail.php
├─valcode.php
├─register_chk.php
├─activation.php
├─mail.class.php -- 邮件类
├─maillogin.php --发送完邮件的返回页,可以登录邮箱和再次发送邮件
├─reactivation.php --用户选择是重新发送激活邮件还是返回注册页
├─remail.php --超时重新发送邮件
├─remailajax.php --点击再次发送邮件
├─remail.php --重新发送邮件
├─showval.php --生产验证码
├─arial.ttf

└─Zend

数据库:

CREATE TABLE `user` ( `id` int(11) NOT NULL auto_increment, `uname` varchar(14) character set utf8 collate utf8_bin NOT NULL default '', `upwd` varchar(32) NOT NULL default '', `uemail` varchar(50) NOT NULL default '', `active` tinyint(4) default '0', `count` tinyint(4) default '0', `activekey` varchar(32) NOT NULL default '' COMMENT '注册时生成的key,用于激活验证', `regdate` int(11) default NULL COMMENT '注册时间', `lockurl` tinyint(4) default '0' COMMENT '超过激活时间m没有激活,就把该值置为1', PRIMARY KEY (`id`), UNIQUE KEY `uemail` (`uemail`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 


标签: PHP+jQuery 注册 模块 改进 邮箱 激活


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2024 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持