<?php
/*
* 图片验证码
*
* Author: DYmyw
* Email: dymayongwei@163.com
* Date: 2012/03/15
* Version:1.0
*/
session_start();
$pic = imagecreatetruecolor(50, 22);
$gb = imagecolorallocate($pic, 0, 0, 0);
for ($i=1; $i<=50; $i++){
$pixelcolor = imagecolorallocate($pic, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($pic, rand(0, 50), rand(0, 22), $pixelcolor);
}
for ($i=1; $i<=4; $i++){
$verify = dechex(rand(0, 15));
$verifystr .= $verify;
$verifycolor = imagecolorallocate($pic, rand(175, 255), rand(175, 255), rand(175, 255));
imagestring($pic, 6, ($i-1)*10+5, rand(0, 8), $verify, $verifycolor);
}
$_SESSION['verifystr'] = $verifystr;
header("Content-type: image/png");
imagepng($pic);
?>
使用说明:
<img name="VerifyPic" src="VerifyPic.php" title="看不清?点击换一张" border="0" οnclick="this.src='VerifyPic.php?'+Math.random();" style="cursor:hand;" />