用户注册E-mail验证

注册表单页signup.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>
< style type ="text/css" >
body
{
background:url("imgs/bg.gif");
}
</style>
</head>

< body >
   < table width ="350" border ="0" align ="center" cellpadding ="0" cellspacing ="0" >
   < tr >
   < td > < form name ="form1" method ="post" action ="signup_ac.php" >
   < table width ="100%" border ="0" cellspacing ="4" cellpadding ="0" >
   < tr >
   < td colspan ="3" > < strong >注册 </strong> </td>
   </tr>
   < tr >
   < td width ="76" >用户名 </td>
   < td width ="3" >: </td>
   < td width ="305" > < input name ="name" type ="text" id ="name" size ="30" > </td>
   </tr>
   < tr >
   < td >E-mail </td>
   < td >: </td>
   < td > < input name ="email" type ="text" id ="email" size ="30" > </td>
   </tr>
   < tr >
   < td >密码 </td>
   < td >: </td>
   < td > < input name ="password" type ="password" id ="password" size ="30" > </td>
   </tr>
   < tr >
   < td >国家 </td>
   < td >: </td>
   < td > < input name ="country" type ="text" id ="country" size ="30" > </td>
   </tr>
   < tr >
   < td >  </td>
   < td >  </td>
   < td > < input type ="submit" name ="Submit" value ="提交" >  
   < input type ="reset" name ="Reset" value ="重置" > </td>
   </tr>
   </table>
   </form> </td>
   </tr>
   </table>    
</body>
</html>
 
表单处理页面signup_ac.php:
 
<?php
include('config.php');

// 表名
$tbl_name="tmp_members";//临时表

//随机确认码
$confirm_code=md5(uniqid(rand()));

//表达传送的值
$name=$_POST['name'];
$email=$_POST['email'];
$country=$_POST['country'];

//插入数据
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password, country)VALUES('$confirm_code', '$name', '$email', '$password', '$country')";
$result=mysql_query($sql);

// 如果数据插入成功则发送验证码给指定E-mail
if($result){

// ---------------- 发送邮箱----------------

//发送给 ...
$to=$email;

// 主题
$subject="您的确认链接";

// 来自
$header="from:admin < HOHO@localhost >";

//你的消息
$message="你的确认链接 \r\n";
$message.="单击此连接激活你的账户 \r\n";
$message.="http://localhost/ex/confirm.php?passkey=$confirm_code";

//发送邮件
$sentmail = mail($to,$subject,$message,$header);

}else {
// 如果没找到
echo "数据库中没有此邮箱";
}

// 如果邮箱发送成功
if($sentmail){
echo "您的确认链接地址已经发送到您的E-mail中.";
}else {
echo "发送邮箱失败";
}
?>
 
数据库配置config.php:
 
<?php
$host="localhost"; // 主机名
$username="root"; // Mysql 用户名
$password="123456"; // Mysql密码
$db_name="verifyemail"; // 数据库名

//连接服务器并选择数据库
mysql_connect("$host", "$username", "$password")or die("不能连接数据库服务器");
mysql_select_db("$db_name")or die("不能选择数据库");
?>
 
 
确认confirm.php
 
<?php
include('config.php');

// 从连接地址得到通行密钥
$passkey=$_GET['passkey'];

$tbl_name1="tmp_members";

// 检索数据寻找匹配密钥的那条记录
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1);

// 查询成功
if($result1){

// 统计下多少行含有此密钥
$count=mysql_num_rows($result1);

//如果找到则获取数据
if($count==1){

$rows=mysql_fetch_array($result1);
$name=$rows['name'];
$email=$rows['email'];
$password=$rows['password'];
$country=$rows['country'];

$tbl_name2="reg_members";

// 把数据插入到注册会员表中
$sql2="INSERT INTO $tbl_name2(name, email, password, country)VALUES('$name', '$email', '$password', '$country')";
$result2=mysql_query($sql2);
}
// 如果没有找到则显示确认码不正确
else {
echo "错误的验证码";
}

// 插入成功的话提示用户已经激活
if($result2){

echo "您的账户已经激活";

// 从临时表中删除记录
$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
$result3=mysql_query($sql3);
}
}
?>
 
 
 
 

你可能感兴趣的:(PHP,职场,验证,email,休闲)