大家在注册一个账号是往往会用到邮箱,服务器会在邮箱中发送激活码,这里是我用到的一个激活
<?php
session_start();
require_once('email.class.php');
//形成表单
//获取表单数据库$_post['input'
//stripslashes() 取消反斜械函数
//addslashches 添加斜械函数
//第二种办法 php.ini
//要求用户具备编辑主配置文件的权限
//magic_uotes_gpc = on | off
//将表单数据写入数据表tb1_user
//$sql
//mysql_query()
//$rs=mysql_fetch_array()
@$username=$_POST['name'];
@$password1=$_POST['pass1'];
@$password2=$_POST['pass2'];
@$email=$_POST['mail'];
if($password1!=""&&$password2!=""&&$password1==$password2){
?>
<script type="text/javascript" language="javascript">
if(/[a-zA-Z0-9-_.]+@[a-zA-Z0-9-_.]+.[a-zA-Z0-9-_.]+/.test(<?php $email ?>)){
alert('邮箱格式错误');
location.href="reg.php";
}
</script>
<?php
//连接数据库
include "./include/dbConn.php";
@$sql="insert into tb_reg value(null,'".$username."','".$password1."','".$email."','".date("Y/m/d")."',"."0".",'".md5($username)."')";
mysql_query($sql);
//将信息写入数据库
$sql="select mdname from tb_reg where username='".$username."'";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
$smtpserver = "smtp.163.com";//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = 123456@163.com; //发信人的邮箱
$smtpemailto = $email; //接受人的邮箱,此处为注册人的邮箱
//echo $smtpemailto;
$smtpuser = "你的邮箱号"; //smtp.163.com 验证
@$smtppass = ""; //你的邮箱密码
$mailsubject = "激活码";
$mailbody = "<a href=http://localhost/mail/works/do_reg.php?name=".$username."&password=".$password1.">点此激活</a>This is a test mail";
$mailtype = "HTML";
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);
$smtp->debug = FALSE;
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
?>
<script type="text/javascript" language="javascript">
alert('注册成功,请激活');
location.href="login.php";
</script>
<?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=utf-8" />
<title>会员注册</title>
</head>
<body>
<form action="reg.php" method="post" onSubmit="check_form()">
<table align="center">
<tr>
<td align="right">用户名:</td>
<td><input type="text" id="name" name="name" onChange="/^[\da-zA-Z]+$/.test(this.value)|| alert('用户名有非法字符!');" size="20" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" id="pass1" name="pass1" size="20" onChange="/^[\da-zA-Z]+$/.test(this.value)|| alert('密码有非法字符!');" /></td>
</td>
<tr>
<td align="right">再次输入密码:</td>
<td><input type="password" id="pass2" name="pass2" size="20" onChange="/^[\da-zA-Z]+$/.test(this.value)|| alert('密码有非法字符!');" /></td>
</tr>
<tr>
<td align="right">邮箱:</td>
<td><input type="text" id="mail" name="mail" size="20" onChange="/[a-zA-Z0-9-_.]+@[a-zA-Z0-9-_.]+.[a-zA-Z0-9-_.]+/.test(this.value)||alert('邮箱格式不正确!');" /></td>
</tr>
<!-- <tr>
<td align="right">E_mail:</td>
<td><input type="text" id="e_mail" name="edit[e_mail]" size="30" /></td>
</tr>
<tr>
<td align="right">性别:</td>
<td><input type="radio" value="男" />
男
<input type="radio" value="女" />
女</td>
</tr>-->
<tr>
<td colspan="2" align="center"><input type="submit" name="ok" value="register" o/></td>
</tr>
<!-- javascript验证各项信息4的有效性:
<form οnsubmit="return check_form() >
<input οnclick="return check_form()" />-->
</table>
</form>
<script type="text/javascript" language="javascript">
function check_form(){
//使用getElementById方法得到指定名称的标签
var username=document.getElementById("name").value;
var password1=document.getElementById("pass1").value;
var password2=document.getElementById("pass2").value;
var email=document.getElementById("mail").value;
//判断用户名不能为空
if(username==""){
alert('用户名不能为空!!!');
//location.href="reg.php";
return false;
}
//判断密码输入是否为空
if(password1==""||password2==""){
alert('密码不能为空!');
return false;
//location.href="reg.php";
}else if(password1==password2){
<?php
$test=true;
?>
return ture;
//location.href="login.php";
}else {
alert('密码不一致');
//location.href="reg.php";
return false;
}
if(email==""&&/[a-zA-Z0-9-_.]+@[a-zA-Z0-9-_.]+.[a-zA-Z0-9-_.]+/.test(email)){
alert('邮箱格式错误');
location.href="reg.php";
}
}
</script>
</body>
</html>