To enhance the security of user logon, we add verification codes on the user authentication page, such as registration and logon. The verification code uses GD to generate a PNG image, and assigns $ randval random numbers to $ _ SESSION ['login _ check_num ']. the verification code is compared with $ _ POST, to determine whether it is correct. "> <LINKhref =" ht
To enhance the security of user logon, we add verification codes on the user authentication page, such as registration and logon.
The verification code uses GD to generate a PNG image, and assigns $ randval random numbers to $ _ SESSION ['login _ check_num ']. the verification code is compared with $ _ POST, to determine whether it is correct. To achieve the required functions, you need to modify the php. ini file so that php supports the GD Library.
// Call this page. if the following formula is set up, a verification code image is generated.
If ($ _ GET ["action"] = "verifycode ")
{
Rand_create ();
}
// Verification code image generation
Function rand_create ()
{
// Notify the browser that a PNG image will be output
Header ("Content-type: image/PNG ");
// Prepare the random number generator seeds
Srand (double) microtime () * 1000000 );
// Prepare image parameters
$ Im = imagecreate (62,20 );
$ Black = ImageColorAllocate ($ im, 0); // RGB black identifier
$ White = ImageColorAllocate ($ im, 255,255,255); // RGB white identifier
$ Gray = ImageColorAllocate ($ im, 200,200,200); // RGB gray identifier
// Start plotting
Imagefill ($ im, 0, 0, $ gray );
While ($ randval = rand () % 100000) <10000 );{
$ _ SESSION ["login_check_num"] = $ randval;
// Print the four-digit integer verification code into the image
Imagestring ($ im, 5, 10, 3, $ randval, $ black );
}
// Add interference pixels
For ($ I = 0; I I <200; $ I ++ ){
$ Randcolor = ImageColorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ im, rand () % 70, rand () % 30, $ randcolor );
}
// Output verification image
ImagePNG ($ im );
// Destroy the image identifier
ImageDestroy ($ im );
}
// Verify the verification code
Function rand_check ()
{
If ($ _ POST ["reg_rand"] = $ _ SESSION ["login_check_num"]) {
Return true;
}
Else {
Exit ("incorrect verification code ");
}
}
?>