1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <?php
session_start();
define("CAPTCHA_NUMCHARS", 4);
$_SESSION['verifyCode']=""; $passPhrase = "";
for ($i = 0; $i < CAPTCHA_NUMCHARS; $i++) { $passPhrase .= chr(rand(97, 122)); } $_SESSION['verifyCode']=$passPhrase;
define("CAPTCHA_WIDTH", 250);
define("CAPTCHA_HEIGHT", 100);
$img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT);
$bgColor = imagecolorallocate($img, 57, 61, 73);
$textColor = imagecolorallocate($img, 255, 255, 255);
$graphicColor = imagecolorallocate($img, 255, 87, 34);
imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bgColor);
for ($i = 0; $i < 10; $i++) { imageline($img, 0, rand() % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphicColor); }
for ($i = 0; $i < 20; $i++) { imagefilledellipse($img, rand() % CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, 10, 10, $graphicColor); }
imagettftext($img, 60, 0, 20, CAPTCHA_HEIGHT - 20, $textColor, "font/ALGER.TTF", $passPhrase);
header("Content-type: image/png"); imagepng($img);
imagedestroy($img); ?>
|