首页 > 作文

用Php编写注册后Email激活验证的实例代码

更新时间:2023-04-06 12:21:54 阅读: 评论:0

总共需两个页面,register.php 和 verify.php

1. 用户注册表格 register.php

复制代码 代码如下:

<html>

<body>

<form action=”register.php” method=”post” name=”register”>

用户名:<input type=”text” name=”urname” />

密码:<input type=”password” name=”password” />

电子邮件:<input type=”text” name=”email” />

<input type=”submit” value=”注册” />

</form>

</body>

</html>

2. 创建用户数据表格 urs

复制代码 代码如下:

create table if not exists `urs` (

`id` int(11) not null auto_increment,

`status` varchar(20) not null,

`urname` varchar(20) not null,

`password` varchar(20) not null,

`email` varchar(20) not null,

`activationkey` varchar(100) not null,

primary key (`id`),

unique key `urname` (`urname`),

unique key `email` (`email`),

unique key `activationkey` (`activationkey`)

) engine=myisam default chart=latin1 auto_increment=9 ;

3. 创建验证码 用户注册信息存入数据表
我们使用状态‘verify’ 来表示尚未激活的用户。

复制代码 代码如下:

$activationkey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();

$urname = mysql_real_escape_string($_post[urname]);

$password = mysql_real_escape_string($_post[password]);

$email = mysql_real_escape_string($_post[email]);

$sql=”inrt into urs (urname, password, email, activationkey, status) values (‘$urname’, ‘$password’, ‘$email’, ‘$activationkey’, ‘verify’)”;

4. 发送验证码

复制代码 代码如下:

echo “an email has been nt to $_post[email] with a燃烧与灭火n activation key. plea check your mail to complete registration.”;

##nd activation email

$to = $_post[email];

$subject = ” yourwebsite.com registration”;

$message = “welcome to our website!\r\ryou, or someone using your email address, has completed基因突变是什么原因引起的 registration at yourwebsite.com. you can complete registration by clicking the following link:\rhttp://www.yourwebsite.com/verify.php?$activationkey\r\rif this is an error, ignore this email 陕西高考成绩and you will be removed from our mailing list.\r\rregards,\ yourwebsite.com team”;

$headers = ‘from: noreply@ yourwebsite.com’ . “\r\n” .

‘reply-to: noreply@ yourwebsite.com’ . “\r\n” .

‘x-mailer: php/’ . phpversion();

mail($to, $subject, $message, $headers);

5. 验证激活代码 verify.php
如果验证码相同,则激活用户。

复制代码 代码如下:

$querystring = $_rver[‘query_string芜湖长江大桥’];

$query = “lect * from urs”;

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){

if ($querystring == $row[“activationkey”]){

echo “congratulations!” . $row[“urname”] . 党风廉政工作总结” is now the proud new owner of a yourwebsite.com account.”;

$sql=”update urs t activationkey = ”, status=’activated’ where (id = $row[id])”;

if (!mysql_query($sql)) {

die(‘error: ‘ . mysql_error());

}

// 到这里,用户已经完全激活了账号,你可以将页面跳转到登陆后的界面了

}

} // end of while

本文发布于:2023-04-06 12:21:32,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/9144ba1b2b663d24ba3f491e565347f8.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:用Php编写注册后Email激活验证的实例代码.doc

本文 PDF 下载地址:用Php编写注册后Email激活验证的实例代码.pdf

标签:代码   验证码   用户   长江大桥
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图