<?PHP//set session, must be at the top of the scriptsession_start (); $image= Imagecreatetruecolor ( -, -);//1> function to set captcha picture size//set the captcha color imagecolorallocate (int im, int red, int green, int blue);$bgcolor = Imagecolorallocate ($image,255,255,255);//#ffffff//Zone fills an int imagefill (int im, int x, int y, int col) (x, y) where the area is shaded, and col represents the color to be paintedImagefill ($image,0,0, $bgcolor); //Setting Variables$captcha _code =""; //Generate random numbers for($i =0; $i <4; $i + +){ //Set Font size$fontsize =6; //set Font color, random color$fontcolor = Imagecolorallocate ($image, Rand (0, -), Rand (0, -), Rand (0, -));//0-120 Dark Color//Set Number$fontcontent = rand (0,9); //Defining variables continuously$captcha _code. =$fontcontent; //Set coordinates$x = ($i * -/4) +rand (5,Ten); $y= rand (5,Ten); Imagestring ($image, $fontsize, $x, $y, $fontcontent, $fontcolor); } //Save to session$_session['Authcode'] =$captcha _code; //add interference elements, set snowflake dots for($i =0; $i < $; $i + +){ //set the color of the point, 50-200 color is lighter than the number, do not disturb reading$pointcolor = Imagecolorallocate ($image, Rand ( -, $), Rand ( -, $), Rand ( -, $)); //imagesetpixel-draw a single pixelImagesetpixel ($image, Rand (1, About), Rand (1, in), $pointcolor); } //add interference elements, set horizontal lines for($i =0; $i <4; $i + +){ //set the color of a line$linecolor = Imagecolorallocate ($image, Rand ( the, -), Rand ( the, -), Rand ( the, -)); //set line, 2.1-wireImageline ($image, Rand (1, About), Rand (1, in), Rand (1, About), Rand (1, in), $linecolor); } //set the head, Image/pngHeader'Content-type:image/png'); //imagepng () Creating PNG graphics functionsimagepng ($image); //Imagedestroy () End graph function Destroy $imageImagedestroy ($image);
Form.php submitted Forms
<?PHP Header ("Content-type:text/html;charset=utf-8");//Set Header information//isset () detects if the variable is set if(Isset ($_request['Authcode']) {session_start (); //strtolower () lowercase function if(Strtolower ($_request['Authcode']) = = $_session['Authcode']){ //Jump PageEcho"<script language=\ "javascript\" >"; Echo"document.location=\ "./form.php\""; Echo"</script>"; }Else{ //tips and Jump pagesEcho"<script language=\ "javascript\" >"; Echo"alert (' Input error! ');"; Echo"document.location=\ "./zhuce.html\""; Echo"</script>"; } exit (); }
Generation of "native" verification codes