PHP + Ajax verification code to verify user login _ php instance

Source: Internet
Author: User
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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.