PHP--TP Framework----How to generate a verification code

Source: Internet
Author: User

how the TP framework----generate a verification code

Xianshi.html

<! 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

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.