Currently, many websites use verification codes to prevent users from actively registering, logging on, and injecting water using robots. The so-called verification code refers to a string of randomly generated numbers or symbols, a natural picture, the picture with some interference pixels (-
Currently, many websites use verification codes to prevent users from actively registering, logging on, and injecting water using robots. The so-called verification code refers to a string of randomly generated numbers or symbols, a natural picture, the picture with some interference pixels (to prevent OCR), the user can identify the verification code information with the naked eye, enter the form and submit the website for verification. after the verification is successful, you can apply a function.
?? Here we show you how to write a PHP program to implement the verification code:
?? Code 1:
/*
* Filename: authpage. php
* Author: huuworm
* Date: 2004-09-26
* @ Copyleft huuworm.org
*/
Srand (double) microtime () * 1000000 );
// Verify whether the entered user is consistent with the verification code
If (isset ())
{
If (strcmp (,) = 0)
Echo 'verification successful! ';
Else
Echo 'verification failed! ';
}
// A new four-digit integer verification code
While (= rand () 000) <1000 );
?>
?? Code 2:
/*
* Filename: authimg. php
* Author: huuworm
* Date: 2003-04-28
* @ Copyleft huuworm.org
*/
// Native verification code Image
Header ('content-type: image/PNG ');
Srand (double) microtime () * 1000000 );
= Imagecreate (58,28 );
= ImageColorAllocate (, 0, 0 );
= ImageColorAllocate (, 255,255,255 );
= ImageColorAllocate (, 200,200,200 );
Imagefill (, 68, 30 ,);
// Print the four-digit integer verification code into the image
Imagestring (, 5, 10, 8 ,,);
For (= 0; <50;) // participates in the interference pixel
{
Imagesetpixel (, rand () p, rand () 0 ,);
}
ImagePNG ();
ImageDestroy ();
???>
?? This program runs in Apache 2.0.45 PHP 4.3.1.
The above is only a brief implementation of the verification code function, and the commercial security Title is not considered. To enhance security and put this effect into commercial use, you can follow these steps:
1. enable Session.
2. authnum is born in authimg. php, and md5sum is calculated and stored in session.