Use PHP to implement the Random verification code function-PHP source code

Source: Internet
Author: User
Ec (2); currently, many websites use the verification code technology to prevent users from automatically registering, logging on, And bumping through robots. The so-called verification code is to generate an image with a string of randomly generated numbers or symbols, and add some interference pixels to the image (preventing OCR). The user can identify the verification code information with the naked eye, enter a form to submit the website for verification. A function can be used only after the verification is successful. Here we show how to write a PHP program to implement the verification CODE function: CODE 1: CODE: & lt ;? Php & nbsp script ec (2); script




Currently, many websites have adopted
Verification code technology. The so-called verification code is to generate an image by generating a random string of numbers or symbols,
Add some interference pixels to the image (preventing OCR), and the user can identify the verification code information with the naked eye.
Enter the form and submit the website for verification. A function can be used only after the verification is successful.

Here we show how to write a PHP program to implement the verification code function:

Code 1:
CODE:
/*
* Filename: authpage. php
* Author: huuworm
* Date: 2003-04-28
* @ Copyleft huuworm.org
*/

Srand (double) microtime () * 1000000 );

// Verify that the user input is consistent with the verification code
If (isset ($ HTTP_POST_VARS [''authinput'])
{
If (strcmp ($ HTTP_POST_VARS [''authnum''], $ HTTP_POST_VARS [''authinput']) = 0)
Echo "Verification Successful! ";
Else
Echo "Verification Failed! ";
}

// Generate a new four-digit integer Verification Code
While ($ authnum = rand () % 10000) <1000 );
?>




Enter the verification code: <

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.