很考眼力的验证码
2012-1-30 18:32 Monday  

分类: PHP 评论(36) 浏览(12014)

<?php
/**
 * 很考眼力的验证码
 * @author Aboc QQ:9986584
 */
header("Content-type: image/gif");
session_start();
$im = imagecreate(60, 25);
$bgcolor = imagecolorallocate($im, rand(150, 255),rand(150, 255), rand(150, 255));
imagefill($im, 0, 0, $bgcolor);
$str = "ABCDEFGHIJKLMNPQRSTUVWXYacdefghijkmnpqrstuvwxy3456789";
$strlength = strlen($str)-1;
$s = $str[mt_rand(0, $strlength)].$str[mt_rand(0, $strlength)].$str[mt_rand(0, $strlength)].$str[mt_rand(0, $strlength)];
$t = array();
$t[1] = imagecolorallocate($im, rand(0, 150), rand(0, 150), rand(0, 150));
$t[2] = imagecolorallocate($im, rand(0, 150), rand(0, 150), rand(0, 150));
$t[3] = imagecolorallocate($im, rand(0, 150), rand(0, 150), rand(0, 150));
$t[4] = imagecolorallocate($im, rand(0, 150), rand(0, 150), rand(0, 150));
imagestring($im, 5, rand(0,7), rand(0,8), $s[0], $t[1]);
imagestring($im, 5, rand(13,22), rand(0,8), $s[1], $t[2]);
imagestring($im, 5, rand(28,37), rand(0,8), $s[2], $t[3]);
imagestring($im, 5, rand(43,50), rand(0,8), $s[3], $t[4]);
$c = array();
for ($i=1;$i<=20;$i++){
    $cl = imagecolorallocate($im, rand(220, 255), rand(220, 255), rand(220, 255));
    $x = rand(0,60);
    $y = rand(0,25);
    imageline($im, $x, $y, $x+rand(-3,3), $y+rand(-2,2), $t[1]);
}
$_SESSION['water'] = $s;
unset($s);
unset($t);
unset($cl);
imagegif($im);
imagedestroy($im);

+1 8

留下你的看法: