您的位置:首页 > 编程语言 > PHP开发

用php实现用户的注册并且有邮箱验证

2011-11-07 20:24 1096 查看
用户的登录注册可以说是我们经常要写的一些简单代码,今天我先给大家带来用php写的用户的注册别且有邮箱的验证

<?php

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['password']."','".@$_POST['mail']."'].@$_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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: