主要的代码
数据库
CREATE TABLE `lw_users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(50) NOT NULL,
`password` varchar(250) default NULL,
`groupid` int(11) NOT NULL,
`picurl` varchar(150) default NULL,
`date` varchar(250) NOT NULL,
`pay` int(11) NOT NULL,
`balance` int(11) NOT NULL,
`mail` varchar(255) NOT NULL,
UNIQUE KEY `id` (`id`)
) ;
CODE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>注册</title>
<meta name="author" c />
<meta name="keywords" c>
<meta name="description" c />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="ajaxreg.js"></script>
</head>
<body>
<script>
function validateform()
{
if (document.tx1.name.value=="")
{
window.alert ("输入姓名")
return false;
}
if (document.tx1.password.value=="")
{
window.alert ("输入密码")
return false;
}
if (document.tx1.repassword.value=="")
{
window.alert ("再次输入密码")
return false;
}
if (document.tx1.repassword.value!=document.tx1.password.value)
{
window.alert ("2次输入密码不一样")
return false;
}
}
</script>
<?php include "config.php" ?>
<?php include "include/header.htm" ?>
<?php
if($_POST[B2] == "")
{
echo "
<form enctype = 'multipart/form-data' method = 'POST' action = 'register.php' name = 'tx1'
onsubmit = 'return validateform(this.form)'>
<div class='old_test'>
<div class='new_test'>
用户名
<input type='text' name='name' id='js_name' onBlur='CallServer_name()'>
<div id='name_check'></div>
</div>
<br/>
<div class='new_test'>
Email
<input type='text' name='email' id='js_email' onBlur='CallServer_email()'>
<div id='email_check'></div>
</div>
<br/>
<div class='new_test'>
密 码
<input type='password' name='password' id='userpwd' onBlur='checkpass()'>
<div id='password2'></div>
</div>
<br/>
<div class='new_test'>
再次输入密码
<input type='password' name='repassword' id='reuserpwd' onBlur='checkpass1()'>
<div id='password3'></div>
</div>
<br/>
<div class='new_test'>
头像url
<input type='text' name='photo' >
</div>
<div class='new_test'>
上传头像
<input type='file' name='userfile'>
</div>
<br/>
<div class='message_left'>
<input type='submit' name='B2' value='注册' />
</div>
</div>
</form>
";
}else
{
if($_POST[name] != "")
{
if($_POST[photo] == "")
{
$uploadaction = 0;
$timelimit = 60;
$uploaddir = 'upload/';
$uploadfile = $uploaddir.$_FILES['userfile']['name'];
$tmpfile = $_FILES['userfile']['tmp_name'];
$file_size = $_FILES['userfile']['size'];
$error = $_FILES['userfile']['error'];
if(($tmpfile != "none") && ($tmpfile != ""))
{
$strfile = (string)$file_size."字节";
}
if ( !in_array( strtolower( $_FILES['userfile']['type'] ) , array( "image/jpg" , "image/gif" , "text/plain","application/octet-stream" ) ) )
{
echo "你发布的图片类型不正确或没有选择头像";
} else{
if(!file_exists($uploadfile))
{
if(move_uploaded_file($tmpfile,$uploadfile))
{
echo "文件上传成功";
$success=1;
//echo $_FILES['userfile']['type'];
}else{
echo "上传失败";
echo "$error";
print_r($_FILES);
echo "<a href='add.php'>点击返回</a>";
}
}else{
echo "文件重名";
echo "<a href='add.php'>点击返回</a>";
}
}
set_time_limit(30);
}else{
$uploadfile = $_POST[photo];
}
$query = "select * from lw_users where username = '$_POST[name]'";//链接表
$result = mysql_db_query($lw_dbname,$query);//执行结果
$row = @mysql_num_rows($result);//行数
}
if($row == 0)
{
if($uploadfile == "")
{
$uploadfile = "upload/default.gif";
}
$day = date("H.m.d");
$query = "INSERT INTO `lw_users` (`id`,`username`,`mail`,`password`,`groupid`,`picurl`,`date`) values(null,'$_POST[name]','$_POST[email]','$_POST[password]','3','$uploadfile','$day')";
$result = mysql_query($query);
mysql_close($connect);
echo "<br/>";
echo "<div class='message_right'>";
echo "注册成功,正在跳转";
echo "</div>";
echo "<meta http-equiv='Refresh' content='3;URL=../index.php'>";
}else{
echo "用户名已存在";
echo "<meta http-equiv='Refresh' content='1;URL=login.php'>";
}
}
?>
<?php include "include/foot.htm" ?>
</body>
</html>
check-name.php和check-email.php
CODE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php include "config.php" ?>
<?php
// header('Content-Type:text/html;charset=GB2312');
//echo "loading...";
//sleep(1);
$js_name=$_GET["js_name"];
//$username=trim($_GET['username']);
$query = "select * from lw_users where username = '$js_name'";//链接表
$result = mysql_db_query($lw_dbname,$query);//执行结果
$row = @mysql_num_rows($result);//行数
if($row == 0)
{
echo "Users who have not been registered";
}else{
echo "Users who have already been registered";
}
?>
</body>
</html>
CODE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php include "config.php" ?>
<?php
$js_email=$_GET["js_email"];
//echo "$js_email";
$query = "select * from lw_users where mail = '$js_email'";//链接表
$result = mysql_db_query($lw_dbname,$query);//执行结果
$row = @mysql_num_rows($result);//行数
if($row == 0)
{
echo "email have not been registered";
}else{
echo "email have already been registered";
}
?>
</body>
</html>
数据库
CREATE TABLE `lw_users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(50) NOT NULL,
`password` varchar(250) default NULL,
`groupid` int(11) NOT NULL,
`picurl` varchar(150) default NULL,
`date` varchar(250) NOT NULL,
`pay` int(11) NOT NULL,
`balance` int(11) NOT NULL,
`mail` varchar(255) NOT NULL,
UNIQUE KEY `id` (`id`)
) ;
CODE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>注册</title>
<meta name="author" c />
<meta name="keywords" c>
<meta name="description" c />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="ajaxreg.js"></script>
</head>
<body>
<script>
function validateform()
{
if (document.tx1.name.value=="")
{
window.alert ("输入姓名")
return false;
}
if (document.tx1.password.value=="")
{
window.alert ("输入密码")
return false;
}
if (document.tx1.repassword.value=="")
{
window.alert ("再次输入密码")
return false;
}
if (document.tx1.repassword.value!=document.tx1.password.value)
{
window.alert ("2次输入密码不一样")
return false;
}
}
</script>
<?php include "config.php" ?>
<?php include "include/header.htm" ?>
<?php
if($_POST[B2] == "")
{
echo "
<form enctype = 'multipart/form-data' method = 'POST' action = 'register.php' name = 'tx1'
onsubmit = 'return validateform(this.form)'>
<div class='old_test'>
<div class='new_test'>
用户名
<input type='text' name='name' id='js_name' onBlur='CallServer_name()'>
<div id='name_check'></div>
</div>
<br/>
<div class='new_test'>
<input type='text' name='email' id='js_email' onBlur='CallServer_email()'>
<div id='email_check'></div>
</div>
<br/>
<div class='new_test'>
密 码
<input type='password' name='password' id='userpwd' onBlur='checkpass()'>
<div id='password2'></div>
</div>
<br/>
<div class='new_test'>
再次输入密码
<input type='password' name='repassword' id='reuserpwd' onBlur='checkpass1()'>
<div id='password3'></div>
</div>
<br/>
<div class='new_test'>
头像url
<input type='text' name='photo' >
</div>
<div class='new_test'>
上传头像
<input type='file' name='userfile'>
</div>
<br/>
<div class='message_left'>
<input type='submit' name='B2' value='注册' />
</div>
</div>
</form>
";
}else
{
if($_POST[name] != "")
{
if($_POST[photo] == "")
{
$uploadaction = 0;
$timelimit = 60;
$uploaddir = 'upload/';
$uploadfile = $uploaddir.$_FILES['userfile']['name'];
$tmpfile = $_FILES['userfile']['tmp_name'];
$file_size = $_FILES['userfile']['size'];
$error = $_FILES['userfile']['error'];
if(($tmpfile != "none") && ($tmpfile != ""))
{
$strfile = (string)$file_size."字节";
}
if ( !in_array( strtolower( $_FILES['userfile']['type'] ) , array( "image/jpg" , "image/gif" , "text/plain","application/octet-stream" ) ) )
{
echo "你发布的图片类型不正确或没有选择头像";
} else{
if(!file_exists($uploadfile))
{
if(move_uploaded_file($tmpfile,$uploadfile))
{
echo "文件上传成功";
$success=1;
//echo $_FILES['userfile']['type'];
}else{
echo "上传失败";
echo "$error";
print_r($_FILES);
echo "<a href='add.php'>点击返回</a>";
}
}else{
echo "文件重名";
echo "<a href='add.php'>点击返回</a>";
}
}
set_time_limit(30);
}else{
$uploadfile = $_POST[photo];
}
$query = "select * from lw_users where username = '$_POST[name]'";//链接表
$result = mysql_db_query($lw_dbname,$query);//执行结果
$row = @mysql_num_rows($result);//行数
}
if($row == 0)
{
if($uploadfile == "")
{
$uploadfile = "upload/default.gif";
}
$day = date("H.m.d");
$query = "INSERT INTO `lw_users` (`id`,`username`,`mail`,`password`,`groupid`,`picurl`,`date`) values(null,'$_POST[name]','$_POST[email]','$_POST[password]','3','$uploadfile','$day')";
$result = mysql_query($query);
mysql_close($connect);
echo "<br/>";
echo "<div class='message_right'>";
echo "注册成功,正在跳转";
echo "</div>";
echo "<meta http-equiv='Refresh' content='3;URL=../index.php'>";
}else{
echo "用户名已存在";
echo "<meta http-equiv='Refresh' content='1;URL=login.php'>";
}
}
?>
<?php include "include/foot.htm" ?>
</body>
</html>
check-name.php和check-email.php
CODE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php include "config.php" ?>
<?php
// header('Content-Type:text/html;charset=GB2312');
//echo "loading...";
//sleep(1);
$js_name=$_GET["js_name"];
//$username=trim($_GET['username']);
$query = "select * from lw_users where username = '$js_name'";//链接表
$result = mysql_db_query($lw_dbname,$query);//执行结果
$row = @mysql_num_rows($result);//行数
if($row == 0)
{
echo "Users who have not been registered";
}else{
echo "Users who have already been registered";
}
?>
</body>
</html>
CODE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php include "config.php" ?>
<?php
$js_email=$_GET["js_email"];
//echo "$js_email";
$query = "select * from lw_users where mail = '$js_email'";//链接表
$result = mysql_db_query($lw_dbname,$query);//执行结果
$row = @mysql_num_rows($result);//行数
if($row == 0)
{
echo "email have not been registered";
}else{
echo "email have already been registered";
}
?>
</body>
</html>
ajaxreg.js
CODE:
<?php
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject()
{
var xmlHttp;
try
{
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
var XmlHttpVersions = new Array("MSXML2.XMlHTTP.6.0",
"MSXML2.XMlHTTP.5.0",
"MSXML2.XMlHTTP.4.0",
"MSXML2.XMlHTTP.3.0",
"MSXML2.XMlHTTP",
"Microsoft.XMlHTTP");
for(var i=0;i<XmlHttpVersions.length && !xmlHttp;i++)
{
try
{
xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
}
catch (e) {}
}
}
if(!xmlHttp)
alert("Error crearing XMLHttpRequest");
else
return xmlHttp;
}
function CallServer_name()
{
var js_name=document.getElementById("js_name").value;
if (js_name!="")
{
var url ="check-name.php?js_name="+js_name; //UTF-8下要用encodeURI
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleRequestStateChange_name;
xmlHttp.send(null);
}else
{
nameDiv = document.getElementById("name_check");
nameDiv.innerHTML = "Users were not empty";
//alert("请您填写用户名!");
}
}
function CallServer_email()
{
var js_email=document.getElementById("js_email").value;
if (js_email!="")
{
// myDiv = document.getElementById("email_check");
// myDiv.innerHTML = "js_name";
var url ="check-email.php?js_email="+js_email; //UTF-8下要用encodeURI
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleRequestStateChange_email;
xmlHttp.send(null);
}else
{
myDiv = document.getElementById("email_check");
myDiv.innerHTML = "email were not empty";
//alert("请您填写用户名!");
}
}
function handleRequestStateChange_name()
{
nameDiv = document.getElementById("name_check");
if(xmlHttp.readyState < 4)
{
// nameDiv.innerHTML = "loading...<br/>";
}
else if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
try
{
nameDiv.innerHTML=xmlHttp.responseText;
}
catch (e)
{
alert("error" + e.toString());
}
}
else
{
alert("problrm" + e.toString());
}
}
}
function handleRequestStateChange_email()
{
// alert("请您填写用户名!");
myDiv = document.getElementById("email_check");
if(xmlHttp.readyState < 4)
{
// myDiv.innerHTML = "loading...<br/>";
}
else if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
try
{
myDiv.innerHTML=xmlHttp.responseText;
}
catch (e)
{
alert("error" + e.toString());
}
}
else
{
alert("problrm" + e.toString());
}
}
}
function checkpass1()
{
var Inform="tx1";
var Inputname="repassword";
var Form=Inform+"."
eval("Temp="+Form+Inputname+".value;");
//alert(Temp);
if(Temp==""){
msg="此项不能为空";
}
else
{
if(Temp.length<6||Temp.length>20)
{
msg="密码必须在6~20个字符之间";
}
else
{
var Inputname1="password";
eval("Temp1="+Form+Inputname1+".value");
if (Temp!=Temp1)
{
eval(Form+Inputname+".value='';");
eval(Form+Inputname1+".value='';");
eval(Form+Inputname1+".focus();");
msg="两次密码不一样!";
msg1="";
var ch1=document.getElementById("password2");
ch1.innerHTML="<font color='#aaaaaa'>"+msg1+"</font>";
}
else
{
msg="输入正确";
}
}
}
var ch=document.getElementById("password3");
ch.innerHTML="<font color='#aaaaaa'>"+msg+"</font>";
}
function checkpass()
{
var Inform="tx1";
var Inputname="password";
var Form=Inform+"."
eval("Temp="+Form+Inputname+".value;");
//alert(Temp);
if(Temp==""){
msg="此项不能为空";
}
else
{
if(Temp.length<6||Temp.length>20)
{
msg="密码必须在6~20个字符之间";
}
else
{
msg="输入正确";
}
}
var ch=document.getElementById("password2");
ch.innerHTML="<font color='#aaaaaa'>"+msg+"</font>";
}
?>
转载自phpchina论坛的十象
CODE:
<?php
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject()
{
var xmlHttp;
try
{
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
var XmlHttpVersions = new Array("MSXML2.XMlHTTP.6.0",
"MSXML2.XMlHTTP.5.0",
"MSXML2.XMlHTTP.4.0",
"MSXML2.XMlHTTP.3.0",
"MSXML2.XMlHTTP",
"Microsoft.XMlHTTP");
for(var i=0;i<XmlHttpVersions.length && !xmlHttp;i++)
{
try
{
xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
}
catch (e) {}
}
}
if(!xmlHttp)
alert("Error crearing XMLHttpRequest");
else
return xmlHttp;
}
function CallServer_name()
{
var js_name=document.getElementById("js_name").value;
if (js_name!="")
{
var url ="check-name.php?js_name="+js_name; //UTF-8下要用encodeURI
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleRequestStateChange_name;
xmlHttp.send(null);
}else
{
nameDiv = document.getElementById("name_check");
nameDiv.innerHTML = "Users were not empty";
//alert("请您填写用户名!");
}
}
function CallServer_email()
{
var js_email=document.getElementById("js_email").value;
if (js_email!="")
{
// myDiv = document.getElementById("email_check");
// myDiv.innerHTML = "js_name";
var url ="check-email.php?js_email="+js_email; //UTF-8下要用encodeURI
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleRequestStateChange_email;
xmlHttp.send(null);
}else
{
myDiv = document.getElementById("email_check");
myDiv.innerHTML = "email were not empty";
//alert("请您填写用户名!");
}
}
function handleRequestStateChange_name()
{
nameDiv = document.getElementById("name_check");
if(xmlHttp.readyState < 4)
{
// nameDiv.innerHTML = "loading...<br/>";
}
else if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
try
{
nameDiv.innerHTML=xmlHttp.responseText;
}
catch (e)
{
alert("error" + e.toString());
}
}
else
{
alert("problrm" + e.toString());
}
}
}
function handleRequestStateChange_email()
{
// alert("请您填写用户名!");
myDiv = document.getElementById("email_check");
if(xmlHttp.readyState < 4)
{
// myDiv.innerHTML = "loading...<br/>";
}
else if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
try
{
myDiv.innerHTML=xmlHttp.responseText;
}
catch (e)
{
alert("error" + e.toString());
}
}
else
{
alert("problrm" + e.toString());
}
}
}
function checkpass1()
{
var Inform="tx1";
var Inputname="repassword";
var Form=Inform+"."
eval("Temp="+Form+Inputname+".value;");
//alert(Temp);
if(Temp==""){
msg="此项不能为空";
}
else
{
if(Temp.length<6||Temp.length>20)
{
msg="密码必须在6~20个字符之间";
}
else
{
var Inputname1="password";
eval("Temp1="+Form+Inputname1+".value");
if (Temp!=Temp1)
{
eval(Form+Inputname+".value='';");
eval(Form+Inputname1+".value='';");
eval(Form+Inputname1+".focus();");
msg="两次密码不一样!";
msg1="";
var ch1=document.getElementById("password2");
ch1.innerHTML="<font color='#aaaaaa'>"+msg1+"</font>";
}
else
{
msg="输入正确";
}
}
}
var ch=document.getElementById("password3");
ch.innerHTML="<font color='#aaaaaa'>"+msg+"</font>";
}
function checkpass()
{
var Inform="tx1";
var Inputname="password";
var Form=Inform+"."
eval("Temp="+Form+Inputname+".value;");
//alert(Temp);
if(Temp==""){
msg="此项不能为空";
}
else
{
if(Temp.length<6||Temp.length>20)
{
msg="密码必须在6~20个字符之间";
}
else
{
msg="输入正确";
}
}
var ch=document.getElementById("password2");
ch.innerHTML="<font color='#aaaaaa'>"+msg+"</font>";
}
?>
转载自phpchina论坛的十象