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 ',),);