Home > Backend Development > PHP Tutorial > Verification code login function implemented by thinkPHP

Verification code login function implemented by thinkPHP

不言
Release: 2023-03-25 11:34:01
Original
2952 people have browsed it

This article mainly introduces the verification code login function implemented by thinkPHP, and analyzes the related implementation techniques of the verification code login verification function of thinkPHP. Friends in need can refer to the following

The examples in this article describe the verification implemented by thinkPHP Code login function. Share it with everyone for your reference, the details are as follows:

Use thinkphp’s own verification to verify the account password verification code on the login page

<?php
  namespace Admin\Controller;
  use Think\Controller;
  use Think\Verify;
  class LoginController extends Controller{
    public function login(){
      if($_POST){
        $obj = new Verify();
        if($obj->check(I(&#39;post.yanzhengma&#39;,&#39;&#39;,&#39;trim&#39;))){
          // 注释部分为另外一种从数据库中验证密码的方法
          // $data[&#39;name&#39;] = I(&#39;post.user_name&#39;);
          // $data[&#39;psd&#39;] = I(&#39;post.password&#39;);
          // $row = M(&#39;user&#39;)->where($data)->find();
          $name = I(&#39;post.user_name&#39;);
          $psd = I(&#39;post.password&#39;);
          $str = &#39;name ="&#39;.$name. &#39;" and tel = "&#39;.$psd.&#39;"&#39;;
          var_dump($str);
          $row = M(&#39;user&#39;)->where($str)->find();
          if($row)
            $this->redirect("Index/index");
          else
            $this->redirect(&#39;login&#39;,&#39;&#39;,1,&#39;用户名或密码错误&#39;);
        }
        else{
          $this->redirect(&#39;login&#39;,&#39;&#39;,1,&#39;验证码错误&#39;);
        }
      }
      $this->display();
    }
    public function verifyImg(){
      //设置验证码的宽高字体大小以及验证码的个数,设计其他的参照Think\Verify里面的设置
      $config=array(
        &#39;imageW&#39;  => 150,
        &#39;imageH&#39;  => 40,
        &#39;fontSize&#39; => 20,
        &#39;length&#39;  => 4
      );
      $obj = new \Think\Verify($config);
      $obj->entry();
    }
  }
Copy after login

Form part

<form action="login" method="post">
  <table valign="top" width="50%">
 <tr><td colspan="2"><h4 style="letter-spacing:1px;font-size:16px;">RainMan 网站管理后台</h4></td></tr>
 <tr><td>管理员:</td><td><input type="text" name="user_name" value="" /></td></tr>
 <tr><td>密    码:</td><td><input type="password" name="password" value="" /></td></tr>
 <tr><td>验证码:</td>
   <td><input type="text" name="yanzhengma" value="" style="width:80px;"/></td>
   <td><img src="__URL__/verifyImg" onclick="this.src=&#39;__URL__/verifyImg/&#39;+Math.random()" alt=""/></td>
 </tr>
 <tr class="bt" align="center"><td> <input type="submit" value="登陆" /></td><td> <input type="reset" value="重填" /></td></tr>
  </table>
</form>
Copy after login

Related recommendations:

thinkPHP method to implement multi-field fuzzy matching query

thinkphp implements file upload and file download


##

The above is the detailed content of Verification code login function implemented by thinkPHP. For more information, please follow other related articles on the PHP Chinese website!

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