<?
php
session_start();
function random(
$len){
$srcstr = "1a2s3d4f5g6hj8k9l0qwertyuiopzxcvbnm"
;
mt_srand();
$strs = ""
;
for(
$i=0;
$i<
$len;
$i++
){
$strs.=
$srcstr[
mt_rand(0,10
)];
}
return $strs;
}
$str = random(4
);
$width = 50
;
$height = 25
;
@header("Content-Type:image/png"
);
$im = imagecreate(
$width,
$height);
$back = imagecolorallocate(
$im,0xFF,0xFF,0xFF
);
$font = imagecolorallocate(
$im,41,163,238
);
$pix = imagecolorallocate(
$im,187,230,247
);
mt_srand();
for(
$i=0;
$i<1000;
$i++
){
imagesetpixel($im,
mt_rand(0,
$width),
mt_rand(0,
$height),
$pix);
}
imagestring($im,5,7,5,
$str,
$font);
imagerectangle($im,0,0,
$width-1,
$height-1,
$font);
imagepng($im);
imagedestroy($im);
$str=
md5(
$str);
setcookie("authcode",
$str,
time()+3600,"/"
);
?>
转载于:https://www.cnblogs.com/SnowZhang/p/6770633.html