<?php
session_start();
$captch_code='';
$weight=100;
$height=30;
$image = imagecreatetruecolor($weight,$height);
$bgcolor=imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$bgcolor);
//数字验证码
/*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);
}*/
//字母数字
for($i=0;$i<4;$i++){
$fontsize =6;
$fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
$data='abcdefghijklmnpqrstuvwxy13456789';
$fontcontent = substr($data,rand(0,strlen($data)-1),1);
$captch_code.=$fontcontent;
$x=($i*$weight/4)+rand(5,10);
$y=rand(5,$height-20);
imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}
$_SESSION['authcode']=$capth_code;
//干扰元素,点
for($i=0;$i<200;$i++){
$pointcolor=imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
imagesetpixel($image,rand(1,$weight-1),rand(1,$height-1),$pointcolor);
}
//线
for($i=0;$i<3;$i++){
$linecolor=imagecolorallocate($image,rand(80,220),rand(80,220),rand(80,220));
imageline($image,rand(1,$weight-1),rand(1,$height-1),rand(1,$weight-1),rand(1,$height-1),$linecolor);
}
header('content-type:image/png');
imagepng($image);
imagedestroy($image);
?>
自己少打个字母...