<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
1.
"2" "1"
"1" Make an object out of the class of the verification code.
"2" calls the method in the object, by entry ()----can generate a verification code.
The class of the verification code----Verify.class.php
<?phpnamespace home\controller;//The namespace of this file uses Think\controller;//use to name the empty-in. Find the Controller parent class file//http://localhost/thinkphp/index.php/home/diyi/testclass Diyicontroller extends controller { Verification Code Function YZM ()//yzm--operation method { //First step, the object that made the captcha $v = new \think\verify ();//Find the class by namespace. Think under the initial namespace, there are methods in the Verify.class.php//Call Object $v->entry ();//Call this entry () method to generate a verification code } function Xianshi () {//This method executes yes, prints the page out $this->display (); } }
The results displayed:
2.
This page needs to generate multiple verification codes-----How to differentiate??
Entry () method can write parameters, write parameters represent the identification code to distinguish between the first few
3.
Example:
<?phpnamespace home\controller;//The namespace of this file uses Think\controller;//use to name the empty-in. Find the Controller parent class file//http://localhost/thinkphp/index.php/home/diyi/testclass Diyicontroller extends controller { Captcha function YZM ()//yzm--operation method { $config = Array (' fontSize ' + = ' length ' = 3, ); $v = new \think\verify ($config); $v->entry (); In the first step, the object that made the captcha $v = new \think\verify ();//The class is found through the namespace. Think under the initial namespace, there are methods in the Verify.class.php//Call Object $v->entry ();//Call this entry () method to generate a verification code } function Xianshi () {//This method executes yes, prints the page out $this->display (); } }
Add parameters to the verification code
The results displayed:
4, the font of the verification code
TTFs to have the appropriate file:
"2" "1"
"1" Font files in English
"2" Chinese font file
This property allows you to set which font to use
5, the background image of the verification code
USEIMGBG default is False, to be changed to true. After the change,随机使用 ThinkPHP/Library/Think/Verify/bgs 目录下面的图片。
the background picture file of the verification code
Example:
<?phpnamespace home\controller;//The namespace of this file uses Think\controller;//use to name the empty-in. Find the Controller parent class file//http://localhost/thinkphp/index.php/home/diyi/testclass Diyicontroller extends controller { Captcha function YZM ()//yzm--operation method { $config = Array (' fontSize ' + = ' length ' = 3, ' useimgbg ' = true, ); $v = new \think\verify ($config); $v->entry (); In the first step, the object that made the captcha $v = new \think\verify ();//The class is found through the namespace. Think under the initial namespace, there are methods in the Verify.class.php//Call Object $v->entry ();//Call this entry () method to generate a verification code } function Xianshi () {//This method executes yes, prints the page out $this->display (); } }
Background image for verification code
The results displayed:
First time, refresh:
Second time, refresh:
6. Chinese Verification Code
To find a font file:
Must be in TTF format
Copy the above file to
<?phpnamespace home\controller;//The namespace of this file uses Think\controller;//use to name the empty-in. Find the Controller parent class file//http://localhost/thinkphp/index.php/home/diyi/testclass Diyicontroller extends controller { Captcha function YZM ()//yzm--operation method { $config = Array (' fontSize ' + = ' length ' = = 3,//' USEIMGBG ' + true, ' usezh ' = = True, ' fontttf ' = ' Simkai.ttf ', ); $v = new \think\verify ($config); $v->entry (); In the first step, the object that made the captcha $v = new \think\verify ();//The class is found through the namespace. Think under the initial namespace, there are methods in the Verify.class.php//Call Object $v->entry ();//Call this entry () method to generate a verification code } function Xianshi () {//This method executes yes, prints the page out $this->display (); } }
fontttf=‘‘表示:所示用哪一个字体。fontttf =‘要写字体的文件名’
The results displayed:
If only ' Usezh ' is set to true, the font cannot be found because it is used by default in English
PHP--TP Framework----How to generate a verification code