Files
image-pichost/captcha.php
2025-11-30 13:05:45 +00:00

43 lines
1.1 KiB
PHP

<?php
session_start();
header('Content-type: image/png');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
$width = 120;
$height = 40;
$chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
$code = '';
for ($i = 0; $i < 4; $i++) {
$code .= $chars[rand(0, strlen($chars) - 1)];
}
$_SESSION['captcha'] = $code;
$image = imagecreate($width, $height);
$bg_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);
$noise_color = imagecolorallocate($image, 200, 200, 200);
for ($i = 0; $i < 100; $i++) {
imagesetpixel($image, rand(0, $width), rand(0, $height), $noise_color);
}
for ($i = 0; $i < 5; $i++) {
imageline($image, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), $noise_color);
}
$font = 5;
$x = 10;
for ($i = 0; $i < 4; $i++) {
$char_color = imagecolorallocate($image, rand(0, 150), rand(0, 150), rand(0, 150));
imagestring($image, $font, $x, rand(8, 12), $code[$i], $char_color);
$x += 25;
}
imagepng($image);
imagedestroy($image);
?>