Implementation of the thinkphp Verification Code (form, ajax implementation verification), thinkphpajax
Two verification Codes, One is directly verified by the form submission button, and the other is verified by passing parameters through ajax:
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 ',),);
The above section describes how to implement the thinkphp Verification Code (form and ajax verification). I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!