When we want to useAdd a line to the php.ini first: Extension=php_gd2.dll
Restart Apache. Make a test page var_dump (Gd_info ()); The output data indicates that the PHP GD Library Reference was successful.
Form auth.html
- <html>
- <head>
- < Meta http-equiv='content-type ' Content=' text/ html Charset=utf-8 '>
- < title > Verification Code title>
- head>
- <body>
- < H1 > Please enter a 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="commit">
- form>
- body>
- html>
PHP GD Library generated verification code auth.php
- php
- Session_Start ();
- Header ("Content-type:image/png");
- $ Img_width = - ;
- $ Img_height = - ;
- 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 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 empty ';
- Die
- }
- if ($auth==$_session[' Check_auth '))
- {
- Echo ' right ';
- }
- Else
- {
- Echo ' ERROR: Verification code input error ';
- }
- ?>
The above is the introduction of the PHP GD library generated verification code related knowledge, we hope to help.
http://www.bkjia.com/PHPjc/446427.html www.bkjia.com true http://www.bkjia.com/PHPjc/446427.html techarticle when we want to use first add a line 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 Reference was successful. Form ...