This article mainly introduces thinkphp's built-in verification code, which is very good and has reference value. if you need it, you can refer to the front-end page:
// Public function Verify () {ob_clean (); // display the verification code $ cfg = array ('codeset' => '2016 ', // the verification code character set is in combination with 'imageh '=> 25, // The verification code Image height is 'imagew' => 80, // The verification code Image width is 'length' => 4, // Number of digits of the verification code '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: