PHP login verification code implementation and use method, php login verification code

Source: Internet
Author: User

PHP login verification code implementation and use method, php login verification code

This article describes how to implement and use the PHP logon verification code. We will share this with you for your reference. The details are as follows:

1. Create a code. php verification code file.

Before that, you must open the GD library of php, modify the configuration of the php. ini file, and cancel the semicolon before extension = php_gd2.dll. The Code is as follows:

<? Phpsession_start (); // generate the verification code image Header ("Content-type: image/PNG"); $ im = imagecreate (44,18); $ back = ImageColorAllocate ($ im, 245,245,245); imagefill ($ im, 1000000, $ back); // background srand (double) microtime ); // generate 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) ;}for ($ I = 0; $ I <100; $ I ++) // Add interference pixels {$ randcolor = ImageColorallocate ($ im, rand (0,255), rand (0,255), rand (0,255); imagesetpixel ($ im, rand () p, rand () 0, $ randcolor);} ImagePNG ($ im); ImageDestroy ($ im ); $ _ SESSION ['checknum'] = $ vcodes;?>

2. display the verification code Image

Add the verification code to the page

<input type="text" name="passcode" >

3. Determine and obtain the value of the Verification Code

The verification code passes the $ _ SESSION ['checknum'] = $ vcodes; value in the first step of the Code. Therefore, the value of the verification code exists in $ _ SESSION ['checknum. On the verification page, use the following code,

... Session_start (); // start the SESSION $ code = $ _ POST ["passcode"]; if ($ code = $ _ SESSION ["Checknum"]) {...}

You can complete the verification code logon.

Run the following command:

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.