Giter Site home page Giter Site logo

think-captcha's Introduction

think-captcha

thinkphp6 验证码类库

安装

composer require topthink/think-captcha

使用

在控制器中输出验证码

在控制器的操作方法中使用

public function captcha($id = '')
{
	return captcha($id);
}

然后注册对应的路由来输出验证码

模板里输出验证码

首先要在你应用的路由定义文件中,注册一个验证码路由规则。

\think\facade\Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");

然后就可以在模板文件中使用

<div>{:captcha_img()}</div>

或者

<div><img src="{:captcha_src()}" alt="captcha" /></div>

上面两种的最终效果是一样的

控制器里验证

使用TP的内置验证功能即可

$this->validate($data,[
    'captcha|验证码'=>'require|captcha'
]);

或者手动验证

if(!captcha_check($captcha)){
 //验证失败
};

think-captcha's People

Contributors

lait233 avatar liu21st avatar normal-coder avatar tianheng2017 avatar yunwuxin avatar zhaishuaigan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.