The GD graphics library wrote a verification code

xiaoxiao2021-03-06  78

1. Please enter the verification code on the right:

>

2, auth_img.php

session_start ();

$ IMG_WIDTH = 80;

$ IMG_HEIGHT = 20;

SRAND (microtime () * 100000);

For ($ ti = 0; $ ti <4; $ ti )

{

$ new_number. = Dechex (Rand (0,15));

}

$ _SESSION [Check_Auth_Number] = $ new_number;

$ Number_Img = ImageCreate ($ IMG_WIDTH, $ IMG_HEIGHT);

ImageColoralLocate ($ Number_Img, 255, 255, 255);

For ($ I = 1; $ i <= 128; $ i )

{

Imagestring ($ Number_img, 1, Mt_Rand (1, $ IMG_WIDTH), MT_RAND (1, $ IMG_HEIGHT), "*", ImageColorallocate ($ Number_img, Mt_Rand (200, 255), MT_RAND (200, 255)));

}

For ($ I = 0; $ I

{

Imagestring ($ Number_Img, Mt_Rand (3,5), $ I * $ IMG_WIDTH / 4 MT_RAND (1, 8), Mt_Rand (1, $ IMG_HEIGHT / 4), $ http_session_vars [Check_Auth_Number] [$ I], ImageColorallocate ($ IMAGECOLORALLOCATE Number_img, mt_rand (0,100), mt_rand (0,150), mt_rand (0,200)));

}

Header ("Content-Type: Image / PNG");

ImagePNG ($ Number_img);

ImageDestroy ($ Number_img);

?>

3, verification part

Function Check_Auth_Number ($ auth_number)

{

IF ($ auth_number! = $ _ session [check_auth_number] || EMPTY ($ _ session [check_AUTH_NUMBER])))

{

Echo "