|
/*
* Verification Code Generation Program
*/
$letter = ";
Get random numbers
for ($i =0; $i <2; $i + +) {
$letter. = Chr (Mt_rand (48,57));
}
Get random letters
for ($i =0; $i <2; $i + +) {
$letter. = Chr (Mt_rand (65,90));
}
Refactoring character Order
$strs = Str_split ($letter);
Shuffle ($STRS);
$rndstring = "";
while (list (, $str) = each ($strs)) {
$rndstring. = $str;
}
If GD is supported, the drawing
if (function_exists ("Imagecreate"))
{
Write cookies to the browser
Setcookie ("Zjs_ckstr", MD5 (Strtolower ($rndstring)), Time () +300, '/');//Verification code valid for 5 minutes
$rndcodelen = strlen ($rndstring);
Picture size
$im = Imagecreate (100,30);
$im = Imagecreatefromgif ("Code.gif");
Font
$font _type = dirname (dirname (__file__)). " /data/font/avantgardebookbt.ttf ";
Background color
$backcolor = Imagecolorallocate ($im, 255,255,255);
Font Color
Imagettftext not supported
$fontColor = Imagecolorallocate ($im, 0,0,0);
Support Imagettftext
$fontColor 2 = imagecolorallocate ($im, 0,0,0);
Shadow
$fontColor 1 = imagecolorallocate ($im, 255,255,25);
Add background clutter
$pixColor = Imagecolorallocate ($im, 199, 199, 199);//Miscellaneous color
for ($j =0; $j <1000; $j + +) {
Imagesetpixel ($im, Rand (0,100), Rand (0,30), $pixColor);
}
Add a background line
for ($j =0; $j <=3; $j + +) {
Background Line Color
$lineColor 1 = imagecolorallocate ($im, rand (0, 255), rand (0, 255), rand (0, 255));
Background line direction size
Imageline ($im, Rand (0,40), Rand (3,25), Rand (40,88), Rand (3,25), $lineColor 1);
}
$strposs = Array ();
Text
for ($i =0; $i < $rndcodelen; $i + +) {
if (function_exists ("Imagettftext")) {
$strposs [$i][0] = $i *16+17;//x axis
$strposs [$i][1] = Mt_rand (20,23);//y axis
Imagettftext ($im, 5, 5, $strposs [$i][0]+1, $strposs [$i][1]+1, $fontColor 1, $font _type, $rndstring [$i]);
} else{
Imagestring ($im, 5, $i *16+7, Mt_rand (2, 4), $rndstring [$i], $fontColor);
}
}
Text
for ($i =0; $i < $rndcodelen; $i + +) {
if (function_exists ("Imagettftext")) {
Imagettftext ($im, 16,5, $strposs [$i][0]-1, $strposs [$i][1]-1, $fontColor 2, $font _type, $rndstring [$i]);
}
}
Header ("Pragma:no-cachern");
Header ("Cache-control:no-cachern");
Header ("Expires:0rn");
Output a specific type of picture format, with a priority of GIF-, JPG
if (function_exists ("Imagegif")) {
Header ("CONTENT-TYPE:IMAGE/GIFRN");
Imagegif ($im);
}else{
Header ("Content-type:image/jpegrn");
Imagejpeg ($im);
}
Imagedestroy ($im);
}
?>
|