Implementation of thinkphp verification code and thinkphp Verification Code

Source: Internet
Author: User

Implementation of thinkphp verification code and thinkphp Verification Code

Two verification codes are used for verification. One is to directly verify the form submission button, and the other is to pass Parameters Using ajax for verification:

1. perform verification directly on the form submission button and write the following code in the Controller VerifyController. class. php:

Namespace Home \ Controller; use Think \ Controller; class VerifyController extends Controller {public function index () {$ this-> display ();} public function checkLogin () {$ verify = new \ Think \ Verify (); $ code = I ('Post. verify '); // Form Verification code if ($ verify-> check ($ code) {$ this-> success ('verification code right ');} else {$ this-> error ('verification code error');} public function verify () {// instantiate the Verify object $ verify = new \ Think \ Verify (); // configure the verification code parameter $ verify-> fontSize = 14; // The Verification Code font size $ verify-> length = 4; // The number of digits of the Verification Code $ verify-> imageH = 34; // Verification Code height $ verify-> useImgBg = true; // enable the verification code background $ verify-> useNoise = false; // disable the verification code interference miscellaneous $ verify-> entry ();}}

The code in Verify/index.html is as follows:

<! DOCTYPE html> 

2. Use ajax to pass Parameters for verification. The code in controller VerifyController. class. php is as follows:

Namespace Home \ Controller; use Think \ Controller; class VerifyController extends Controller {public function index () {$ this-> display ();} public function checkLogin () {$ verify = new \ Think \ Verify (); $ code = $ _ POST ['code']; // obtain the ajax verification code if ($ verify-> check ($ code) {$ this-> ajaxReturn (1 );} else {$ this-> ajaxReturn (0) ;}} public function verify () {// instantiate the Verify object $ verify = new \ Think \ Verify (); // configure the verification code parameter $ verify-> fontSize = 14; // The Verification Code font size $ verify-> length = 4; // The number of digits of the Verification Code $ verify-> imageH = 34; // Verification Code height $ verify-> useImgBg = true; // enable the verification code background $ verify-> useNoise = false; // disable the verification code interference miscellaneous $ verify-> entry ();}}

The code in Verify/index.html is as follows:

<! DOCTYPE html> 

In the 2nd methods, don't forget to download the jquery. min. js file: http://www.jq22.com/jquery-info122

Configure the address in the configuration file Common/conf/config. php:

Return array (/* address replacement */'tmpl _ PARSE_STRING '=> array (' _ JS _ '= >__ ROOT __. '/Public/js ',),);

 

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.