blob: efa6d56a7aec2f810e2db5f48b73ea208f82bdf6 (
plain)
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
|
<?php
if(session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
function IsValidCaptcha($captcha)
{
if(isset($_SESSION['valid_captchas'][$captcha])) {
unset($_SESSION['valid_captchas'][$captcha]);
return true;
}
return false;
}
function GetCaptcha()
{
$letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$word = '';
for ($i = 0; $i < 8;$i++) {
$letter = $letters[random_int(0, strlen($letters)-1)];
$word = $word . $letter;
}
$_SESSION['valid_captchas'][$word] = true;
$image = imagecreate(80, 20);
imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 5, 3, 2, $word, $text_color);
ob_start();
imagepng($image);
$imagestring = ob_get_contents();
ob_end_clean();
imagedestroy($image);
return $imagestring;
}
|