?? Currently, many websites use verification codes 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, syntaxHighlighter. all ();
?? 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:
/*
* 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 );
?>
?? Code 2:
?? /*
* Filename: authimg. php
* Author: huuworm
* Date: 2003-04-28
* @ Copyleft huuworm.org
*/
// Generate a verification code Image
Header ("Content-type: image/PNG ");
Srand (double) microtime () * 1000000 );
$ Im = imagecreate (58,28 );
$ Black = ImageColorAllocate ($ im, 0, 0 );
$ White = ImageColorAllocate ($ im, 255,255,255 );
$ Gray = ImageColorAllocate ($ im, 200,200,200 );
Imagefill ($ im, 68, 30, $ gray );
// Print the four-digit integer verification code into the image
Imagestring ($ im, 5, 10, 8, $ HTTP_GET_VARS [authnum], $ black );
For ($ I = 0; $ I <50; $ I ++) // add interference pixels
{
Imagesetpixel ($ im, rand () % 70, rand () % 30, $ black );
}
ImagePNG ($ im );
ImageDestroy ($ im );
???>
?? This program runs in the Apache 2.0.45 + PHP 4.3.1 environment.