thinkphp implementation function: Verification code

Source: Internet
Author: User

1. Define Verification Code function

Public Function Verify () {/** * How to implement the CAPTCHA in thinkphp * * thinkphp has provided us with an image processing class library thinkphp\extend\ ... * * How do I import a class library? * Import the class library to import with "import (file path), but note the path of the file in the \ to replace." ("* 1) Import the class library of the system  (starting from the library) import (' ORG. Util.image ') Note case * 2) Import the Project class libraries import ("@.org. Image ") We need to store the *///Import Graphics class library (" ORG ") in the Lib directory of my Grace project. Util.image ");//import (" @.org. Image ");//Generate a graphics verification code/*length: the length of the verification code, the default is 4 digits mode: The type of the validation string, the default is a number, the other support type has 0 letters 1 digits 2 Capital Letter 3 lowercase Letter 4 Chinese 5 Mix (remove the easily confusing characters Ooll and number) type: The image type of the verification code, the default is pngwidth: The width of the verification code, by default automatically calculates the height according to the verification code length: The default is 22verifyName: The session record name of the verification code, the default is verify *///implementation of the English Verification Code image::buildimageverify (4,1, ' png ', 60,22, ' verify ');// Implement Chinese Code//image::gbverify ();}

To be blunt is two sentences:

function Verify () {    import ("ORG. Util.image ");    Image::buildimageverify (4,1, ' png ', 60,22, ' Verify ');}

2. Then call in the template

For example:

 <a href= "javascript:show ()" > Unclear </a>< Script>             function Show () {      document.getElementById ("verify"). src= "__url__/verify/random" +math.random () ;                }  

  

thinkphp implementation function: Verification code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.