Php programming verification code, which is required every day. The verification code is required for php programming every day. This article shares the implementation code of the php image verification code for your reference. the specific content is as follows: 1. verification code picture php programming daily required verification code, php programming verification code
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.
Articles you may be interested in:
- Php5 image verification code
- PHP verification code (latest modification, fully customized! )
- A beautiful php verification code class (share)
- Share a handy PHP verification code instance
- Simple ThinkPHP verification code tutorial
- Thinkphp verification code cannot be displayed
- PHP generates image verification codes and click to switch instances
- Captcha verification code instance implemented by php
- Perfect solution to the problem that thinkphp verification code fails to be displayed
This article shares the implementation code of the php image verification code for your reference. The details are as follows: 1. the verification code picture...