PHP验证码生成

今天闲来无事,看着黑白的验证码感觉心里不是很爽,于是就花了点时间改了下。

效果如下:

 

代码如下:Header("Content-type: image/png"); $image = imagecreate(58,25); //定义一张图片 $white = imagecolorallocate($image, 255, 255, 255);//设置背景为白色 //画上雪花 for($i = 1;$i < 50;$i++){ $x = rand(1,53); $y = rand(1,20); $color = imagecolorallocate($image,rand(200,255),rand(200,255),rand(200,255)); imagechar($image, 1, $x, $y, "*", $color); } //画上随机字符,并将字符记录进session变量里 session_start(); $vcode = ''; $charactors = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; for ($i = 0; $i < 4; $i++) { $font = rand(4, 6); $x = rand(4+$i*13, 7+$i*13); $y = rand(4, 7); $charactor = $charactors[rand(0,61)]; $charactor_color = imagecolorallocate($image, rand(0,225), rand(0,150), rand(0,225)); imagestring($image, $font, $x, $y, $charactor, $charactor_color); $vcode .= $charactor; } $_SESSION['vcode'] = $vcode; //显示图片 imagepng($image); imagedestroy($image);  

你可能感兴趣的:(PHP,image,session,header)