Use the PHPGD library to generate a verification code. Add a reference line in php. ini: extensionphp_gd2.dll to restart apache. Make a test page var_dump (gd_info (). the output data indicates that the PHPGD database has been referenced successfully. Form when we want to useAdd a line of reference in php. ini: extension = php_gd2.dll
Restart apache. Make a test page var_dump (gd_info (). the output data indicates that the php gd Library has been referenced successfully.
Table ticket auth.html
- <Html>
- <Head>
- <Meta Http-equiv='Content-type' Content='Text/html; charset = utf-8'>
- <Title>Verification code Title>
- Head>
- <Body>
- <H1>Enter verification code H1>
- <Form Action="Check_auth.php" Method="Post">
- <Input Name="Auth" Type="Text">
- <Img Src="Auth. php" Border="0" />
- <Input Type="Submit" Value="Submit">
- Form>
- Body>
- Html>
Php gd library to generate verification code auth. php
- Php
- Session_start ();
- Header ("Content-type: image/png ");
-
- $Img_width=100;
- $Img_height=20;
-
- Srand (microtime () * 100000 );
- For ($I=0; $ I<4; $ I ++)
- {
- $New_number.=Dechex(Rand (0, 15 ));
- }
-
- $ _ SESSION [check_auth] = $ new_number;
- $New_number=ImageCreate($ Img_width, $ img_height); // create an image
- ImageColorAllocate ($ new_number, 255,255,255); // set the background color to white.
-
- For ($I=0; $ I<Strlen($ _ SESSION [check_auth]); $ I ++)
- {
- $Font=Mt_rand(3, 5 );
- $X=Mt_rand(1, 8) + $ img_width * $ I/4;
- $Y=Mt_rand(1, $ img_height/4 );
- $Color=ImageColorAllocate($ New_number, mt_rand (0,100), mt_rand (0,150), mt_rand (0,200); // set the character color
- ImageString ($ new_number, $ font, $ x, $ y, $ _ SESSION [check_auth] [$ I], $ color); // output character
- }
-
- ImagePng ($ new_number );
- ImageDestroy ($ new_number );
- ?>
Php gd Library submission page check_auth.php
- Php
- Session_start ();
- $Auth= $ _ POST ['auth '];
-
- If (empty ($ auth ))
- {
- Echo 'Error: the verification code cannot be blank ';
- Die;
- }
-
- If ($Auth==$ _ SESSION ['Check _ auth'])
- {
- Echo 'true ';
- }
- Else
- {
- Echo 'Error: incorrect verification code input ';
- }
- ?>
The above is the knowledge about generating verification codes in the php gd library described in this article. I hope it will be helpful to you.
Worker first adds a line of reference in php. ini: extension = php_gd2.dll to restart apache. Make a test page var_dump (gd_info (). the output data indicates that the php gd Library has been referenced successfully. Form...