This article shares the php image verification code for your reference. The details are as follows. captcha is generated for the verification code image. php1. generate an image of the size of 100*30. The default value is black $ imageimagecreatetruecolor (255,255, 30). Create a white basemap $ bgcolorimagecolorallocate ($ image, 25
This article shares the php image verification code for your reference. The details are as follows. captcha is generated for the verification code image. php // 1. generate an image of 100*30. The default value is black $ image = imagecreatetruecolor (255,255, 30); // create a white basemap $ bgcolor = imagecolorallocate ($ image, 25
This article shares the php image verification code for your reference. The details are as follows:
1. Verification Code Image Generation
Captcha. php
// 1. generate an image of 100*30. The default value is black $ image = imagecreatetruecolor (255,255,255, 30); // create a white basemap $ bgcolor = imagecolorallocate ($ image ); // fill in the black imagefill ($ image, $ bgcolor) with white; // 2. random display of numbers or letters $ captch_code = ""; for ($ I = 0; $ I <4; $ I ++) {$ fontsize = 6; $ fontcolor = imagecolorallocate ($ image, rand (0,120), rand (0,120), rand (0,120); $ data = "abcdefghijkmnpqrstuvwxy3456789"; $ fontcontent = substr ($ data, rand (0, strlen ($ data), 1); $ captch_code. = $ fontcontent; $ x = ($ I * 100/4) + rand (); $ y = rand (); imagestring ($ image, $ fontsize, $ x, $ y, $ fontcontent, $ fontcolor);} $ _ SESSION ["authcode"] = $ captch_code; // 3. add disturbance // disturbance point for ($ I = 0; $ I <100; $ I ++) {$ pointcolor = imagecolorallocate ($ image, rand (50,200 ), rand (50,200), rand (50,200); imagesetpixel ($ image, rand (), rand (), $ pointcolor );} // interference line for ($ I = 0; $ I <2; $ I ++) {$ linecolor = imagecolorallocate ($ image, rand (80,220), rand (80,220 ), rand (80,220); imageline ($ image, rand (), rand (), $ linecolor );} header ("content-type: image/png"); imagepng ($ image );
2. Implement the verification code function on the page
Form. php
<?phpif(isset($_POST["authcode"])){ session_start(); if(strtolower($_POST["authcode"])==$_SESSION["authcode"]){ echo "OK"; }else{ echo "NO"; }}?>
Document
The above is all the content of this article, helping you easily implement the php image verification code.