search
Homephp教程php手册thinkPHP中验证码的简单使用方法,

thinkPHP中验证码的简单使用方法,

本文实例讲述了thinkPHP中验证码的简单使用方法。分享给大家供大家参考,具体如下:

首先生成验证码,在action文件中,直接调用thinkphp中提供的方法即可生成,确保开启php的扩展 gd2

如下:

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

同时用SESSION保存生成的验证码的值:复制代码 代码如下:$_SESSION['verify']
注意:保存的是用md5加密之后的值

在对应的tpl文件中,对该验证码进行调用,使用方法如下:
复制代码 代码如下:thinkPHP中验证码的简单使用方法,可实现点击刷新功能

显示效果如下:

用户提交过去的验证码,需要md5加密之后,在与保存的session值进行比较,即:

判断  md5($_POST['verify']  与  $_SESSION[‘verify']  是否相等。

至此完成验证码的基本使用

希望本文所述对大家基于thinkPHP框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

  • ThinkPHP中使用Ueditor富文本编辑器
  • ThinkPHP整合百度Ueditor图文教程
  • ThinkPHP自动转义存储富文本编辑器内容导致读取出错的解决方法
  • thinkPHP中分页用法实例分析
  • thinkPHP下ueditor的使用方法详解
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor