上传文件至 /
This commit is contained in:
43
captcha.php
Normal file
43
captcha.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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);
|
||||
?>
|
||||
Reference in New Issue
Block a user