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