below to share a PHP-produced picture Verification code case: Cases such as:
The use of PHP gd detailed see: http://www.php.net/manual/zh/book.image.php
The background image code is as follows:
<?phpsession_start (); $image = Imagecreatetruecolor (100,30);//Create a picture of width 100, 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 front 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 execute changes as follows:
<p> captcha Image: 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!