The daily required verification code for php programming, and the 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" ;}}?> <! Doctype html>
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