40 行
1.2 KiB
PHP
40 行
1.2 KiB
PHP
<?php
|
|
session_start();
|
|
$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
|
$len = 4;
|
|
$code = '';
|
|
for ($i = 0; $i < $len; $i++) {
|
|
$code .= $chars[random_int(0, strlen($chars) - 1)];
|
|
}
|
|
$_SESSION['captcha'] = $code;
|
|
if (!extension_loaded('gd')) {
|
|
header('Content-Type: text/plain; charset=UTF-8');
|
|
echo $code;
|
|
exit;
|
|
}
|
|
$w = 120; $h = 44;
|
|
$img = imagecreatetruecolor($w, $h);
|
|
$bg = imagecolorallocate($img, 248, 250, 252);
|
|
imagefill($img, 0, 0, $bg);
|
|
for ($i = 0; $i < 6; $i++) {
|
|
$c = imagecolorallocate($img, rand(180, 230), rand(190, 235), rand(200, 245));
|
|
imageline($img, rand(0, $w), rand(0, $h), rand(0, $w), rand(0, $h), $c);
|
|
}
|
|
for ($i = 0; $i < 40; $i++) {
|
|
$c = imagecolorallocate($img, rand(180, 230), rand(190, 235), rand(200, 245));
|
|
imagesetpixel($img, rand(0, $w), rand(0, $h), $c);
|
|
}
|
|
for ($i = 0; $i < $len; $i++) {
|
|
$c = imagecolorallocate($img, rand(20, 90), rand(70, 140), rand(170, 230));
|
|
$size = rand(20, 26);
|
|
$angle = rand(-20, 20);
|
|
$x = 14 + $i * 26;
|
|
$y = rand(30, 38);
|
|
imagestring($img, 5, $x, $y - 16, $code[$i], $c);
|
|
}
|
|
header('Content-Type: image/png');
|
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
|
header('Pragma: no-cache');
|
|
imagepng($img);
|
|
imagedestroy($img);
|