Method for implementing email activation in Yii framework [digital signature]_php example

WBOY
Release: 2023-03-03 06:36:01
Original
982 people have browsed it

The example in this article describes how the Yii framework implements email activation. Share it with everyone for your reference, the details are as follows:

Controller:

//发送邮箱,激活账号
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&#63;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&#63;r=login/login'</script>";
     }
     else
     {
       echo "<script>alert('激活失败');location.href='index.php&#63;r=login/login'</script>";
     }
   }
   else
   {
     echo "<script>alert('参数错误,重新激活');location.href='index.php&#63;r=login/login'</script>";
   }
}

Copy after login

Principle: (After registration, the original default status is status=0. After activation, it is changed to 1 before you can log in.)

Readers who are interested in more Yii-related content can check out the special topics of this site: "Introduction to Yii Framework and Summary of Common Techniques", "Summary of Excellent PHP Development Framework", "Basic Tutorial for Getting Started with Smarty Templates", "Introduction to PHP Object-Oriented Programming" Tutorial", "php string usage summary", "php+mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will help you design PHP programs based on the Yii framework.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!