-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcaptcha.php
30 lines (30 loc) · 982 Bytes
/
captcha.php
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
<?php
session_start();
define('CAPTCHA_WIDTH', 150);
define('CAPTCHA_HEIGHT', 40);
define('CAPTCHA_NUMCHARS',6);
$pass_phrase="";
for($i=0;$i< CAPTCHA_NUMCHARS;$i++)
{
$pass_phrase.=chr(rand(97,122));
}
$_SESSION["captcha"]=$pass_phrase;
$img= imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT);
$bgcolor=imagecolorallocate($img, 225, 225, 225);
$textcolor=imagecolorallocate($img, 0, 0, 0);
$graphiccolor=imagecolorallocate($img, 64, 64, 64);
imagefilledrectangle($img, 0, 0,CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bgcolor);
$font = dirname(__FILE__) . '/ARIALN.TTF';
for($i=0;$i< 4;$i++)
{
imageline($img,0, rand() % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphiccolor);
}
for($i=1;$i< 50;$i++)
{
imagesetpixel($img, rand() % CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphiccolor);
}
imagettftext($img, 24, 0, 20, CAPTCHA_HEIGHT-10, $textcolor, $font, $pass_phrase);
header("Content-type:image/png");
imagepng($img);
imagedestroy($img);
?>