每日博客

时间:大约一个多小时

代码:100来行?

博客:1

知识点:php

<?php
session_start();
require("lineMysql.php");
$email = stripslashes(trim($_POST['mail']));
global $db;
$select = $db->findpwd("user", $email);
$row=$db->rows($select);       #返回的结果集记录总数
if(empty($row)){
    echo 'noreg';
}else{
    $getpasstime = time();
    $token = md5($row['username'].$row['password']);//组合验证码
    $url = "/demo/resetpass/reset.php?email=".$email."
&token=".$token;//构造URL
    $time = date('Y-m-d H:i');
    $result = sendmail($time,$email,$url);
    if($result==1){//邮件发送成功
        $msg = '系统已向您的邮箱发送了一封邮件<br/>请登录到您的邮箱及时重置您的密码!';
//更新数据发送时间
        mysql_query("update `user` set `getpasstime`='$getpasstime' where email='$email '");
    }else{
        $msg = $result;
    }
    echo $msg;
}

//发送邮件
function sendmail($time,$email,$url){
    include_once("smtp.class.php");
    $smtpserver = ""; //SMTP服务器,如smtp.163.com
    $smtpserverport = 25; //SMTP服务器端口
    $smtpusermail = ""; //SMTP服务器的用户邮箱
    $smtpuser = ""; //SMTP服务器的用户帐号
    $smtppass = ""; //SMTP服务器的用户密码
    $smtp = new Smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass);
//这里面的一个true是表示使用身份验证,否则不使用身份验证.
    $emailtype = "HTML"; //信件类型,文本:text;网页:HTML
    $smtpemailto = $email;
    $smtpemailfrom = $smtpusermail;
    $emailsubject = "www.jb51.net - 找回密码";
    $emailbody = "亲爱的".$email.":<br/>您在".$time."提交了找回密码请求。请点击下面的链接重置密码
(按钮24小时内有效)。<br/><a href='".$url."'target='_blank'>".$url."</a>";
    $rs = $smtp->sendmail($smtpemailto, $smtpemailfrom, $emailsubject, $emailbody, $emailtype);

    return $rs;
}
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>注册</title>
</head>
<body>
<form action = "res.php" method = "post">
    <table>
        <tr>
            <td class="left">用户名:</td>
            <td class="center"><input type="text" id="user" class="in" onblur="checkUser()"></td>
            <td>
                <div id="namePrompt"></div>
            </td>
        </tr>
        <tr>
            <td class="left">密码:</td>
            <td class="center"><input type="password" id="pwd" class="in" onblur="checkpwd()"></td>
            <td>
                <div id="pwdPrompt">
                    密码由英文字母和数字组成的4-10位字符
                </div>
            </td>
        </tr>
        <tr>
            <td class="left">
                确认密码:
            </td>
            <td class="center"><input type="password" id="repwd" class="in" onblur="checkRepwd()"></td>
            <td>
                <div id="repwdPrompt"></div>
            </td>
        </tr>
        <tr>
            <td class="left">
                电子邮箱:
            </td>
            <td class="center"> <input type="text" id="email" class="in" onblur="checkEmail()"></td>
            <td>
                <div id="emailPrompt"></div>
            </td>
        </tr>
        <tr>
            <td class="left">手机号码:</td>
            <td class="center"><input type="text" id="mobile" class="in" onblur="checkMobile()"></td>
            <td>
                <div id="mobilePrompt"></div>
            </td>
        </tr>
        <tr>
            <td></td>
            <td ><input type="submit" value="注册" onclick="return check()"></td>
            <td></td>
        </tr>
    </table>

    <script>
        function $(elementId) {
            return document.getElementById(elementId).value;
        }

        function divId(elementId) {
            return document.getElementById(elementId);
        }

        function checkUser(){
            var username = document.getElementById("user");
            var nameId = divId('namePrompt');
            nameId.innerHTML = ' ';
            if(username.value=="")
            {
                nameId.innerHTML = '用户名不能为空';
                return false;
            }
            else
            {
                $.ajax({
                    type : "post",
                    url : 'register.php',
                    data: {username:username},
                    dataType : "json",
                    success : function(reslut){
                        if(reslut=="repeat"){
                            nameId.innerHTML = '用户名已存在';
                            return false;
                        }
                    },
                    error:function(){
                        $(this).html("信息加载失败!");
                        return false;
                    }
                });
            }
            return true;
        }

        function checkpwd() {
            var pwd = $('pwd');
            var pwdId = divId('pwdPrompt');
            pwdId.innerHTMl = ' ';
            var reg = /^[a-zA-z0-9]{4,10}$/;
            if (reg.test(pwd) == false)
            {
                pwdId.innerHTML = '密码不能为空或含有非法字符,长度在4-10之间';
                return false;
            }
            else{pwdId.innerHTML = ' ';}
            return true;
        }

        function checkRepwd() {
            var repwd = $('repwd');
            var pwd = $('pwd');
            var Rpwd = divId('repwdPrompt');
            Rpwd.innerHTMl = '';
            if (pwd != repwd) {
                Rpwd.innerHTML = '两次输入的密码不一致';
                //console.log('密码不一致')
                return false;
            }
            Rpwd.innerHTML = '';
            // console.log('密码一致')
            return true;
        }

        function checkEmail() {
            var email = $('email');
            var emailPrompt = divId('emailPrompt');
            emailPrompt.innerHTML = ' ';
            var reg = /^\w+@\w+(\.[a-zA-Z]{2,3}){1,2}$/;
            if (reg.test(email) == false) {
                emailPrompt.innerHTML = 'Email不能为空或格式不正确,例如web@sohu.com';
                return false;
            }
            return true;
        }

        function checkMobile() {
            var mobile = $('mobile');
            var mobileId = divId('mobilePrompt');
            var regMobile = /^1\d{10}$/;
            if (regMobile.test(mobile) == false) {
                mobileId.innerHTML = '手机号码不能为空或不正确,请重新输入';
                return false;
            }
            mobileId.innerHTML = ' ';
            return true;
        }

        function check() {
            if(checkpwd()&&checkRepwd()&&checkEmail()&&checkMobile()&&checkUser()){return true;}
            else
            {
                alert('注册信息有误,请检查后重新输入!');
                return false;
            }
        }
    </script>
</form>
</body>
</html>

 

posted @ 2021-04-07 21:31  谦寻  阅读(52)  评论(0编辑  收藏  举报