• 邮件激活代码PHP实现


    邮件激活代码实现

    如果用户激活的时间超过24小时,说明激活连接过期,这个时候,重新发送激活邮件;

    //邮箱激活操作
    	public function activate()
    	{
    		//接收超链接身上传递的用户id以及生产的唯一口令
    		$user_id = $_GET['uid'];
    		$acive_code = $_GET['code'];
    		//获得用户模型
    		$m_user = Factory::M('UserModel');
    		//基础模型中,封装过find()方法根据主键查询用户信息
    		//但是当时封装的是protected,如果想在这里使用将其改为public
    		$user = $m_user -> find($user_id);
    		if($user){
    			//激活链接是有效的
    			//判断激活时间是否过期
    			if(time()-$user['active_code_time']>24*3600){
    					
    				//重新发送激活邮件,还需要先生成新的口令并更新数据库
    				$data['user_id'] = $user_id;
    				$data['active_code'] = md5(mt_rand(10000,99999).time());
    				$data['active_code_time'] = time();
    				//将基础模型中的proteced修改为public
    				$m_user -> update($data);
    				$this -> sendMail($user_id,$data['active_code'],$user['email']);
    				
    				$this -> jumpWait('激活链接已过期,重新发送激活邮件,请重新查收并激活',
    				'index.php?m=home&c=user&a=register');
    			}else{
    				//激活成功,更新数据表,将is_active修改为1
    				$data['user_id'] = $user_id;
    				$data['is_active'] = 1;	
    				$m_user -> update($data);
    				
    				//直接登录
    				$this -> jumpNow('index.php?m=home&c=user&a=login');
    			}
    		}else{
    			//没有找到,说明激活链接无效的
    			$this -> jumpWait('激活链接无效','index.php?m=home&c=user&a=register');
    		}
    	}
    
    

    登录判断,邮件激活状态

    image-20220922140437667

  • 相关阅读:
    [one day one question] safari缓存太厉害
    对工厂方法模式的一些思考(2)
    对工厂方法模式的一些思考(java语法表示)
    [选译]MySQL5.7以上Zip版官方安装文档
    clojure 使用阿里云仓库
    对jbox2d引擎的一些回顾与思考(swing实现demo)
    定位
    空白空间及溢出的处理
    BFC
    高度自适应
  • 原文地址:https://www.cnblogs.com/lovebing/p/16719615.html
Copyright © 2020-2023  润新知