register.php
<!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"><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script language="javascript" src="js/xmlhttprequest.js"></script>
<script language="javascript" src="js/register.js"></script>
</head>
<body>
<div id="container">
<div id="rgbgdiv">
<div id="regnamediv"><b>注册名称:</b>
<input id="regname" name="regname" type="text" />
<div id="namediv">请输入用户名</div>
</div>
<div id="regpwddiv1"><b>注册密码:</b>
<input id="regpwd1" name="regpwd1" type="password" />
<div id="pwddiv1">请输入密码</div>
</div>
<div id="regpwddiv2"><b>确认密码:</b>
<input id="regpwd2" name="regpwd2" type="password" />
<div id="pwddiv2">请输入确认密码</div>
</div>
<div id="regemaildiv"><b>电子邮箱:</b>
<input id="email" name="email" type="text" />
<div id="emaildiv">用户激活和找回密码使用</div>
</div>
<div id="morediv" style="display:none;">
<hr id="part" />
<div id="regquestiondiv"><b>密保问题:</b>
<input id="question" name="question" type="text" />
<div id="questiondiv">用户激活和找回密码使用</div>
</div>
<div id="reganswerdiv"><b>密保答案:</b>
<input id="answer" name="answer" type="text" />
<div id="answerdiv">用户激活和找回密码使用</div>
</div>
<div id="regrealnamediv"><b>真实姓名:</b>
<input id="realname" name="realname" type="text" />
<div id="realnamediv">用户的真实姓名</div>
</div>
<div id="regbirthdaydiv"><b>出生日期:</b>
<input id="birthday" name="birthday" type="text" />
<div id="birthdaydiv">用户的出生日期。格式:YYYY-MM-DD</div>
</div>
<div id="regtelephonediv"><b>联系电话:</b>
<input id="telephone" name="telephone" type="text" />
<div id="telephonediv">用户的联系电话</div>
</div>
<div id="regqqdiv"><b>QQ号 码:</b>
<input id="qq" name="qq" type="text" />
<div id="qqdiv">用户QQ号</div>
</div>
</div>
<div id="btndiv2">
<button id="regbtn" disabled="disabled"> </button>
<button id="morebtn"> </button>
<button id="logbtn"> </button>
</div>
</div>
<div id="imgdiv" style=" visibility: hidden;"> </div>
</div>
</body>
</html>
register.js
// JavaScript Document
function $(id){return document.getElementById(id);
}
window.onload = function(){
$('regname').focus();
var cname1,cname2,cpwd1,cpwd2,cemail;
//设置激活按钮
function chkreg(){
if((cname1 == 'yes') && (cname2 == 'yes') && (cpwd1 == 'yes') && (cpwd2 == 'yes') && (cemail == 'yes')){
$('regbtn').disabled = false;
}else{
$('regbtn').disabled = true;
}
}
//验证用户名
$('regname').onkeyup = function (){
name = $('regname').value;
cname2 = '';
if(name.match(/^[a-zA-Z_]*/) == ''){
$('namediv').innerHTML = '<font color=red>必须以字母或下划线开头</font>';
cname1 = '';
}else if(name.length < 2){
$('namediv').innerHTML = '<font color=red>注册名称必须大于等于2位</font>';
cname1 = '';
}else{
$('namediv').innerHTML = '<font color=green>注册名称符合标准</font>';
cname1 = 'yes';
}
chkreg();
}
//验证是否存在该用户
$('regname').onblur = function(){
name = $('regname').value;
if(cname1 == 'yes'){
xmlhttp.open('get','chkname.php?name='+name,true);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
var msg = xmlhttp.responseText;
if(msg == '1'){
$('namediv').innerHTML="<font color=green>恭喜您,该用户名可以使用!</font>";
cname2 = 'yes';
}else if(msg == '2'){
$('namediv').innerHTML="<font color=red>用户名被占用!</font>";
cname2 = '';
}else{
$('namediv').innerHTML="<font color=red>"+msg+"</font>";
cname2 = '';
}
}
}
chkreg();
}
xmlhttp.send(null);
}
}
//验证密码
$('regpwd1').onkeyup = function(){
pwd = $('regpwd1').value;
pwd2 = $('regpwd2').value;
if(pwd.length < 6){
$('pwddiv1').innerHTML = '<font color=red>密码长度最少需要6位</font>';
cpwd1 = '';
}else if(pwd.length >= 6 && pwd.length < 12){
$('pwddiv1').innerHTML = '<font color=green>密码符合要求。密码强度:弱</font>';
cpwd1 = 'yes';
}else if((pwd.match(/^[0-9]*$/)!=null) || (pwd.match(/^[a-zA-Z]*$/) != null )){
$('pwddiv1').innerHTML = '<font color=green>密码符合要求。密码强度:中</font>';
cpwd1 = 'yes';
}else{
$('pwddiv1').innerHTML = '<font color=green>密码符合要求。密码强度:高</font>';
cpwd1 = 'yes';
}
if(pwd2 != '' && pwd != pwd2){
$('pwddiv2').innerHTML = '<font color=red>两次密码不一致!</font>';
cpwd2 = '';
}else if(pwd2 != '' && pwd == pwd2){
$('pwddiv2').innerHTML = '<font color=green>密码输入正确</font>';
cpwd2 = 'yes';
}
chkreg();
}
//验证确认密码
$('regpwd2').onkeyup = function(){
pwd1 = $('regpwd1').value;
pwd2 = $('regpwd2').value;
if(pwd1 != pwd2){
$('pwddiv2').innerHTML = '<font color=red>两次密码不一致!</font>';
cpwd2 = '';
}else{
$('pwddiv2').innerHTML = '<font color=green>密码输入正确</font>';
cpwd2 = 'yes';
chkreg();
}
}
//验证email
$('email').onkeyup = function(){
emailreg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
$('email').value.match(emailreg);
if($('email').value.match(emailreg) == null){
$('emaildiv').innerHTML = '<font color=red>错误的email格式</font>';
cemail = '';
}else{
$('emaildiv').innerHTML = '<font color=green>输入正确</font>';
cemail = 'yes';
}
chkreg();
}
//显示/隐藏详细信息
$('morebtn').onclick = function(){
if($('morediv').style.display == ''){
$('morediv').style.display = 'none';
}else{
$('morediv').style.display = '';
}
}
//登录按钮
$('logbtn').onclick = function(){
window.open('login.php','_parent','',false);
}
//正式注册
$('regbtn').onclick = function(){
$('imgdiv').style.visibility = 'visible';
url = 'register_chk.php?name='+$('regname').value+'&pwd='+$('regpwd1').value+'&email='+$('email').value;
url += '&question=' +$('question').value+'&answer='+$('answer').value;
url += '&realname=' +$('realname').value+'&birthday='+$('birthday').value;
url += '&telephone='+$('telephone').value+'&qq='+$('qq').value;
xmlhttp.open('get',url,true);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
msg = xmlhttp.responseText;
if(msg == '1'){
alert('注册成功,请到您的邮箱中获取激活码!');
location='index.php';
}else if(msg == '-1'){
alert('您的服务器不支持Zend_mail,或者邮箱填写错误。请仔细检查!!');
}else{
alert(msg);
}
$('imgdiv').style.visibility = 'hidden';
}
}
}
xmlhttp.send(null);
}
}
xmlhttprequest.js
var xmlhttp = false;
if (window.XMLHttpRequest) { //Mozilla、Safari等浏览器
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) { //IE浏览器
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
chkname.php
<?php
include_once "conn/conn.php";
$sql = "select * from tb_member where name='".$_GET['name']."'";
$num = $conne->getRowsNum($sql);
if($num == 1){
echo '2';
}else if($num == 0){
echo '1';
}else{
echo $conne->msg_error();
}
?>