Simple method to use verification code in thinkPHP, _PHP tutorial

WBOY
Release: 2016-07-12 09:02:53
Original
720 people have browsed it

A simple way to use the verification code in thinkPHP,

The example in this article describes the simple way to use the verification code in thinkPHP. Share it with everyone for your reference, the details are as follows:

First generate the verification code. In the action file, directly call the method provided in thinkphp to generate it. Make sure to enable the PHP extension gd2

is as follows:

class UserAction Model extends Model
{
/**
 * 显示验证码信息
 */
 public function verify()
 {
     ob_clean(); // 清空(擦掉)输出缓冲区 ,也就是清空前面的输出,通常情况下验证码不显示,可考虑这个问题
     import('ORG.Util.Image');
     Image::buildImageVerify();
  }
}

Copy after login

At the same time, use SESSION to save the value of the generated verification code: Copy the code The code is as follows: $_SESSION['verify']
Note: What is saved is the value encrypted with md5.

In the corresponding tpl file, call the verification code. The usage method is as follows:
Copy code The code is as follows:Click to refresh function

The display effect is as follows:

The past verification code submitted by the user needs to be md5 encrypted and then compared with the saved session value , that is:

Judge whether md5($_POST['verify'] and $_SESSION['verify'] are equal.

This completes the basic use of the verification code

I hope this article will be helpful to everyone’s PHP programming based on the thinkPHP framework.

Articles you may be interested in:

  • Using Ueditor rich text editor in ThinkPHP
  • ThinkPHP integration Baidu Ueditor graphic tutorial
  • ThinkPHP automatic escaping Solution to reading errors caused by storing rich text editor content
  • Instance analysis of paging usage in thinkPHP
  • Detailed explanation of how to use ueditor in thinkPHP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084519.htmlTechArticleThe simple way to use the verification code in thinkPHP. This article describes the simple way to use the verification code in thinkPHP. Share it with everyone for your reference, the details are as follows: First generate the verification code,...
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