邮件激活

PHP页面

<?php
  //用户的注册、激活、登陆、找寻密码
  include 'Mail.class.php';
  header('content-type:text/html;charset=utf-8');
  $act=isset($_GET['act']) ? $_GET['act'] :'';
  $pdo=new PDO('mysql:host=localhost;dbname=1408phpb','root','root');
  $pdo->exec('set names utf8');
 if($act=='register'){
   //接受用户信息
   $username=$_POST['username'];
   $password=$_POST['password'];
   $email=$_POST['email'];
   $question=$_POST['question'];
   $answer=$_POST['answer'];
   $validate=uniqid();
   //入库
   $sql="insert into user(username,password,email,question,answer,validate) values('$username','$password','$email','$question','$answer','$validate')";
   if($pdo->exec($sql)){
      //发送邮件进行激活
      $title='用户注册激活';
      $user='客服美女';
      $address=$email;
      $username1=md5('username');
      $validate1=md5('validate');
   $url="http://www.study.com/seven7/1408phpB/20160323/index.php?act=jihuo&".$username1."=".urlencode($username)."&".$validate1."=".urlencode($validate)."&time=".time();
      $content="请点击以下链接进行激活<br/>"."<a href='$url'>$url</a>";
     if(Mail::send($title,$content,$user,$address)){
        //提示已经发送
        echo "您已经注册成功,请于24小时内进行<a href='http://mail.163.com'>激活</a>";
     }else{
       echo Mail::$error;
     } 
   }
 }elseif($act=='jihuo'){
   //进行邮箱激活
   $username=$_GET[md5('username')];
   $sql="select * from user where username='$username'";
   $row=$pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
   $validate=$_GET[md5('validate')];
   $time=$_GET['time'];
   //判断有没有操作24小时
    if(time()-$time>24*3600){
      echo '邮件激活已过期,请重新注册';
      header('refresh:3;url=http://www.study.com/seven7/1408phpB/20160323/index.php');
      die;
   }
   //有可能该用户已经激活成功
    if($row['status']==1){
      echo '该用户已经激活成功过,请登录';
      header('refresh:3;url=http://www.study.com/seven7/1408phpB/20160323/index.php?act=login');
      die;
   }
   //激活
   if($validate==$row['validate']){
      //更改状态
      $sql="update user set status=1 where username='$username'";
     if($pdo->exec($sql)){
       //激活成功
      echo '该用户成功激活,请登录';
      header('refresh:3;url=http://www.study.com/seven7/1408phpB/20160323/index.php?act=login');
      die;
     }
   }
 }elseif($act=='login'){
   //登陆
   echo 'hello';
 
 }else{
   include 'register.html';
 }



HTML页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
   <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
   <title></title>
</head>
<body>
   <form action="index.php?act=register" method='post'>
    用户名:<input type="text" name='username'/> </br>
    密码:<input type="password" name='password'/> <br />
    邮箱:<input type="text" name='email' /> <br />
    问题:<input type="text" name='question' /><br />
    答案:<input type="text"  name='answer'/><br />
    <input type="submit" value='注册' />
   </form>
</body>
</html>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值