<?php require_once (' string.func.php ');
function Verifyimage ($type =1, $length =4, $pixel =0, $line =0, $sess _name= "verify") {session_start ();
/* Define length and Width */$width = 80;
$height = 30;
* * Create Canvas/$image =imagecreatetruecolor ($width, $height); /* This function is used to match the color of the graphic for use by other drawing functions. The parameter image represents the handle of the graphic.
Parameters red, green, blue are three primary colors of color, with values ranging from 0 to 255 .... I hereby define black and white/$white =imagecolorallocate ($image, 255, 255, 255);
$black =imagecolorallocate ($image, 0,0,0); /* This function will color the enclosed rectangular area of the picture. Parameter x1, y1 and x2, and Y2 are the coordinates of the rectangular diagonal respectively.
Parameter col indicates the color to be painted/Imagefilledrectangle ($image, 1, 1, $width-2, $height-2, $white);
The/*buildrandomstring function is used to generate a CAPTCHA/$chars =buildrandomstring ($type, $length);
/* The validation code is given to the session to determine whether the user input is correct/$_session[$sess _name]= $chars; /* Definition Font Library * * * $fontfiles =array (' Msyh.ttf ', ' Msyhbd.ttf ', ' SIMSUN.TTC ', ' simyou. TTF ', ' Sthupo. TTF ', ' Stkaiti. TTF ', ' Stliti.
TTF ');
/* Use a loop to write the validation code one by one to the image ($i =0; $i < $length; $i + +) {$size =mt_rand (14,18);
$angle =mt_rand ( -15,15);
/* Verification Code of the horizontal axis and ordinate * * * $x =5+ $i * $size;
$y =mt_rand (20,26); $coLor=imagecolorallocate ($image, Mt_rand (50,190), Mt_rand (50,200), Mt_rand (50,90)); $fontfile = ".
/font/". $fontfiles [Mt_rand (0,count ($fontfiles)-1)];
$text =substr ($chars, $i, 1);
/* This function writes TTF (TrueType Fonts) font text to the picture * * Imagettftext ($image, $size, $angle, $x, $y, $color, $fontfile, $text); } if ($pixel) {for ($i =0 $i <50; $i + +) {/* This function can draw a point on the picture.
parameter x, y is the coordinates of the plot point, the parameter col indicates the color of the point/Imagesetpixel ($image, Mt_rand (0, $width-1), Mt_rand (0, $height-1), $black); } if ($line) {for ($i =0 $i <10; $i + +) {$color =imagecolorallocate ($image, Mt_rand (50,90), Mt_rand (50,200), Mt_rand (50
, 90)); /* Draw Segment * * Imageline ($image, Mt_rand (0, $width-1), Mt_rand (0, $height-1), Mt_rand (0, $width-1), Mt_rand (0, $height-1), $
color);
}/* Output the */header ("Content-type:image/gif") in GIF format;
/* Set up GIF map and output to Web page/imagegif ($image);
/* Free memory associated with image/Imagedestroy ($image);
}