/** * 开发团队:逆行者联盟 * 官方地址:www.nxzlm.com * 官方客服:@QiuShuYa */ session_start(); $width = 120; $height = 38; $image = imagecreatetruecolor($width, $height); $bgColor = imagecolorallocate($image, 242, 242, 242); imagefill($image, 0, 0, $bgColor); $captchaCode = ''; $chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz'; for ($i = 0; $i < 4; $i++) { $captchaCode .= $chars[mt_rand(0, strlen($chars) - 1)]; } $_SESSION['captcha'] = strtolower($captchaCode); for ($i = 0; $i < 5; $i++) { $lineColor = imagecolorallocate($image, mt_rand(100, 200), mt_rand(100, 200), mt_rand(100, 200)); imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $lineColor); } for ($i = 0; $i < 50; $i++) { $dotColor = imagecolorallocate($image, mt_rand(150, 250), mt_rand(150, 250), mt_rand(150, 250)); imagesetpixel($image, mt_rand(0, $width), mt_rand(0, $height), $dotColor); } for ($i = 0; $i < 4; $i++) { $textColor = imagecolorallocate($image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); $fontSize = mt_rand(5, 6); $x = ($width / 4) * $i + 10; $y = mt_rand(5, 15); imagestring($image, $fontSize, $x, $y, $captchaCode[$i], $textColor); } header('Content-Type: image/png'); imagepng($image); imagedestroy($image);