本文实例讲述了Yii框架实现邮箱激活的方法。分享给大家供大家参考,具体如下:
控制器:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
//发送邮箱,激活账号
public function actionEmail()
{
$email =Yii:: $app ->request->get( 'email' );
//数字签名
$em_1 =md5( $email );
//邮箱发送
$mail = Yii:: $app ->mailer->compose();
$mail ->setTo( $email );
$mail ->setSubject( "激活邮箱" );
//发布可以带html标签的文本
$mail ->setHtmlBody( "<a href='http://www.small2.com/backend/web/index.php?r=login/live&em_1=" . $em_1 . "&email=" . $email . "'>点击此链接</a>" );
if ( $mail ->send())
echo "success" ;
else
echo "false" ;
die (); //邮箱发送ok
}
//激活账号
public function actionLive()
{
$email =Yii:: $app ->request->get( 'email' );
$em_1 =Yii:: $app ->request->get( 'em_1' );
//echo $em_1;die;
$em_2 =md5( $email );
//echo $em_2;die;
if ( $em_1 == $em_2 )
{
$res =Yii:: $app ->db;
$data = $res ->createCommand()->update( "login" ,[ "status" =>1],[ "email" => $email ])->execute();
if ( $data )
{
echo "<script>alert('激活成功,可登录');location.href='index.php?r=login/login'</script>" ;
}
else
{
echo "<script>alert('激活失败');location.href='index.php?r=login/login'</script>" ;
}
}
else
{
echo "<script>alert('参数错误,重新激活');location.href='index.php?r=login/login'</script>" ;
}
}
|
原理:(注册后原有默认原有状态status=0,激活后改为1,方可登陆。)
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。