用php写的用户的注册别且有邮箱的验证。
代码:
<?php
/**
* PHP用户注册及邮箱验证
* edit: www.jb200.com
*/
require ('email.class.php');
include "dbconnect.php";
include "functions.php";
$form=check_form(@$_POST['edit']);
extract($form);
$username=@$_POST['username'];
$sql="insert into tb_user(id,username,password,mail) values(null,'".@$_POST['username']."','".@$_POST['password']."','".@$_POST['mail']."')";
mysql_query($sql);
@$sql1 = "insert into tb_user(id,username,password,status,md5name) values(null,'{$name}','{$pass}','0',md5('{$name}'))";
$res = mysql_query($sql1);
// echo $mail;
//echo $sql;
//$sql1="select mad5name from tb_user where username='[$name]'";
//mysql_query($sql1);
$smtpserver = "smtp.163.com";//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = "*********";//发信人
@$smtpemailto = $mail;//收信人
$smtpuser = "*************"; //smtp.qq.com需要验证的
$smtppass = "**********";
$mailsubject = "激活码";
$mailbody = "<a href=http://localhost/do_reg.php?id=3>点击http://localhost/do_reg.php?id=3</a>";
$mailtype = "HTML";
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);
$smtp->debug = false;
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
//写入成功跳转到login.php
?>
<!--action="可以当前页面,也可以为另一个独立的php页面"-->
<form action="" method="post" id="user_register">
<table align="center" background="#cccccc">
<tr bgcolor="#CCCCCC"><td colspan="2"><div align="center">会员注册</div></td></tr>
<tr bgcolor="#6699CC">
<td width="80"><div align="right">用户名:</div></td>
<td width="378">
<input type="text" name="edit[name]" id="edit-name" size="30" />
</td>
</tr>
<tr bgcolor="#CCCCCC">
<td><div align="right">密 码:</div></td>
<td>
<input type="password" name="edit[pass]" id="edit-pass" size="30" />
</td>
<tr bgcolor="#6699CC">
<td><div align="right">确认密码:</div></td>
<td>
<input type="password" name="edit[pass2]" id="edit-pass2" size="30" />
</td>
</tr>
<tr bgcolor="#6699CC">
<td width="45"><div align="right">邮箱:</div></td>
<td>
<input type="text" name="edit[mail]" id="edit-mail"/>
</td>
</tr>
<tr bgcolor="#CCCCCC" align="center">
<td colspan="2">
<input type="submit" name="op" value="确认注册" onclick="return check_form()"/>
</td>
</tr>
</table>
</form>
<script language="javascript">
function check_form(){
var username = document.getElementById("edit-name").value;
var password = document.getElementById("edit-pass").value;
var password2 = document.getElementById("edit-pass2").value;
var mail = document.getElementById("edit-mail").value;
var msg ="";
if(username=="")
{
msg+="username is not null! n";
alert(msg);
}
if(password==""){msg+="password is not null! n";
alert(msg);
}
if(password!=password2){msg+="password must equal! n";
alert(msg);
}
if(radiobutton==""){msg+="sex is not null! n";
alert(msg);
}
if(mail==""){msg+="mail is not null! n";
alert(msg);
}
if(msg==""){
alert("成功了");
window.open("login.php");
return true;
}else{
alert("失败了");
return false;
}
}
</script>