This article mainly introduces the PHP + AJAX verification code to verify user login information. one advantage of using AJAX to verify user login is that the jump page is not refreshed, and the verification code is safer, I wrote something about it. Three files are used in total:
Yz. php:The PHP file that generates the verification code. the verification code will be in the SESSION for comparison and call at login.
Index. php:HTML file for user login
LoginCheck. php:Verify the user login file
The following is a one-to-one explanation:
Yz. php file
<? Php session_start (); // Generate the verification code graph Header ("Content-type: image/PNG"); // length and width $ im = imagecreate (44,18 ); // set the background color: $ back = ImageColorAllocate ($ im, 245,245,245); // fill in the background color: imagefill ($ im, $ back); srand (double) microtime () * 1000000); $ vcodes; // generates four digits for ($ I = 0; $ I <4; $ I ++) {$ font = ImageColorAllocate ($ im, rand (100,255), rand (0,100), rand (100,255); $ authnum = rand (); $ vcodes. = $ authnum; imagestring ($ im, 5, 2 + $ I * 10, 1, $ authnum, $ font);} // add interference pixels for ($ I = 0; $ I <100; $ I ++) {$ randcolor = ImageColorallocate ($ im, rand (0,255), rand (0,255), rand (0,255); imagesetpixel ($ im, rand () % 70, rand () % 30, $ randcolor);} ImagePNG ($ im); ImageDestroy ($ im); // save the four-digit verification code in the SESSION, call comparison during logon $ _ SESSION ["VCODE"] = $ vcodes;?>
Index. php:Note: Do not use $ _ SESSION ["VCODE"] in this file; otherwise, the last verification code will be displayed after refreshing.
It's okay to verify it in loginCheck. php.
Admin background | log on