The built-in verification code of thinkphp is fully parsed, and thinkphp is fully parsed.
Front-end page:
<Div style = "position: absolute; z-index: 3; top: 160px; left: 180px;"> </div> // The verification code is used to determine the public function Verify () {ob_clean (); // display the verification code $ cfg = array ('codeset' => '000000', // The Verification Code character set is in combination with 'imageh '=> 25, // The Image Height of the verification code is 'imagew' => 80, // The image width of the verification code is 'length' => 4, // The number of digits of the verification code is 'fontttf' => '4. ttf', // the font of the Verification Code. Do not set the random 'fontsize' => 10, // The font size of the Verification Code (px) 'usenoise '=> false, // whether to add the noise point 'usecurve' => false, // whether to draw the confusion curve 'bg '=> array (226,229,236) // background color ); $ very = new \ Think \ Verify ($ cfg); $ very-> entry ();} // The client verifies the verification code public function checkVerify () through ajax () {$ code = I ('get. code '); $ very = new \ Think \ Verify (); $ key = $ this-> auth_my_code ($ very, $ very-> seKey ); // The Verification code cannot be blank $ secode = session ($ key); // encrypt $ code. if ($ this-> auth_my_code ($ very, strtoupper ($ code) = $ secode ['verify _ Code']) {echo json_encode (array ('flag' => 1, 'cont' => 'correct Verification Code ');} else {echo json_encode (array ('flag' => 2, 'cont' => 'verification code error');} private function auth_my_code ($ vry, $ str) {$ key = substr (md5 ($ vry-> seKey ), 5, 8); $ str = substr (md5 ($ str), 8, 10); return md5 ($ key. $ str );}
If the verification code above is incorrectly entered and cannot be automatically refreshed after submission, after the code is changed:
Location. href = "/Login"; in this way, you can only refresh the entire page. The value of the submitted form may be lost, which affects the user experience.
2. If the verification code is incorrect, the verification code is automatically refreshed after submission.
Else {$ ('# safecode'). attr ("src", "/Login/Verify? "+ Math. random (); NewAlert (2, "Incorrect verification code, please enter", null); code_ OK = false;((('{verifyresult'{.html(msg.cont}.css ({'color': 'red', 'font-size ': '12px '});}
3. The following is the verification code submitted by ajax to the backend for verification:
<Script type = "text/javascript"> $ ("# login_btn "). click (function () {var username = $. trim ($ ("# username "). val (); var password = $. trim ($ ("# password "). val (); var code = $ ('# veri '). val (); if (username = "") {NewAlert (2, "Enter the user name", null); shutdown (); return false ;} else if (password = "") {NewAlert (2, "Enter password", null); shutdown (); return false;} else if (code = '') {NewAlert (2, "Enter the verification code", null); return false;} // ajax verifies the code on the server $. ajax ({Url: "_ CONTROLLER _/checkVerify", data: {'code': code}, dataType: 'json', success: function (msg) {if (msg. flag = 1) {var data = {username: username, password: password}; $. ajax ({type: "POST", url: "{: U ('login/login')}", data: data, dataType: "json", success: function (msg) {if (msg. respCode = '000') {shutdown (); if (msg.org _ code = 'fcb ') {location. href = "/Invest/index? Biao_type = cwb ";} else {location. href = "{$ Think. config. VIP_URL}/Individual/index ";} else {NewAlert (2, msg. respDesc, null); return false ;}, error: function () {shutdown () ;}, beforeSend: function () {Loading ();},});} else {$ ('# safecode '). attr ("src", "/Login/Verify? "+ Math. random (); NewAlert (2, "Incorrect verification code, please enter", null); code_ OK = false;((('{verifyresult'{.html(msg.cont}.css ({'color': 'red', 'font-size ': '12px '}) ;}}}) ;}); </script>
The above is a comprehensive analysis of the thinkphp built-in Verification Code introduced by the small editor. I hope it will be helpful to you. If you have any questions, please leave a message for me. The small editor will reply to you in time. Thank you very much for your support for the help House website!