php生成验证码

<?php
header("content-type:image/gif");
session_start();
$width = 60;
$height = 30;
$img = imagecreatetruecolor($width,$height);
$red = imagecolorallcate($img,rand(0,255),rand(0,255),rand(0,255));
$while = imagecolorallocate($img,182,223,235);
imagefilldrectangle($img,0,0,$width,$height,$while);
$str = "0123456789abcdefghijklmnopqrstwvuxyz";
$num = "";
for($i=0;$i<5;$i++){
    $num .= $str[rand(0,strlen($str)-1)];
}
$_session["num"] = $num;
for($j=0;$j<80;$j++){
    imagesetpixel($img, rand(0,$width), rand(0,$height), $red);
}
for($k=0;$k<6;$k++){
    $col = imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
    imageline($img,rand(0,$width),rand(0,$height),rand(0,$width),rand(0,$height),$col);    
}
imagegettftext($img,16,rand(-5,5),5,20,$red,"include/simhei.ttf",$num);
$imgagegif($img);
imagedestroy($img);


你可能感兴趣的:(php生成验证码)