The following share a PHP-produced picture Verification code case: the ratio of the case to:
Use PHP GD specific see: http://www.php.net/manual/zh/book.image.php
Background picture code such as the following:
<?Phpsession_start (); $image = Imagecreatetruecolor (100,30);//Create a width of 100. Picture of Height 30 $bgcolor=imagecolorallocate ($image, 255,255,255);//Picture background is white Imagefill ($image, 0,0, $bgcolor);//Picture fill white//random number/* *for ($i =0; $i <4; $i + +) {$fontsize = 6; $fontcolor =imagecolorallocate ($image, Rand (0,120), Rand (0,120), Rand (0,120)); $fontcontent =rand (0,9); $x = ($i *100/4) + rand (5,10); $y =rand (5,10); Imagestring ($image, $fontsize, $x, $y, $fontcontent, $fontcolor);} **///random Data $captch_code= '; for ($i =0; $i <4; $i + +) {$fontsize = 6; $fontcolor =imagecolorallocate ($image, Rand (0,120), Rand (0,120), Rand (0,120)); $data = ' asdfdfglfg74erf21854hgfhgfhkg4ljkghjtrtywiqpoqpwepdfgvnjytyut12313345645667686797800 '; $fontcontent =substr ($data, Rand (0,strlen ($DATA)), 1); $captch _code.= $fontcontent; $x = ($i *100/4) + rand (5,10); $y =rand (5,10); Imagestring ($image, $fontsize, $x, $y, $fontcontent, $fontcolor);} $_session[' Authcode ']= $captch _code;//random point for ($i =0; $i <200; $i + +) {$pointcolor =imagecolorallocate ($image, Rand ( 50,120), Rand (50,120), Rand (50,120)); ImageSetPixel ($image, Rand (1,99), Rand (1,99), $pointcolor);} Random line for ($i =0; $i <3; $i + +) {$linecolor =imagecolorallocate ($image, Rand (80,220), Rand (80,220), Rand (80,220)); Imageline ($image, Rand (1,99), Rand (1,29), Rand (1,99), Rand (1,29), $linecolor);} Header ("Content-type:image/png"); Imagepng ($image); imagedestory ($image);? >
The foreground code is as follows:
<?php if (isset ($_request[' Autocode ')) { session_start (); if (Strtolower ($_post[' Autocode ')) = = $_session[' Authcode ']) { echo ' is correct '; } else{ echo ' error '; } Exit (); }? ><! DOCTYPE html>
Add click-to-run changes such as the following:
<p> captcha Image: R= "<?
PHP echo rand ();? > width= "height=" " /> <a href=" javascript:void (0) "onclick=" document.getElementById (' Capthcha_ IMG '). src= ' captcha.php?
R= ' +math.random () "> Change one </a></p>
This case original, reproduced please specify. PHP GD generate image Verification code +session get storage Verification Code