diff options
author | Jonas Kohl | 2024-09-05 21:39:40 +0200 |
---|---|---|
committer | Jonas Kohl | 2024-09-05 21:39:40 +0200 |
commit | c6390e9bb14747de2bc894f817fc6373a7deddaf (patch) | |
tree | fe5628fc820146ecac76758865150e6c166ebfd5 /cgi/captcha.php | |
parent | 5d4652e6bc0009b32bfe1b1a4fc9b7431cd8fe88 (diff) |
Add contact form
Diffstat (limited to 'cgi/captcha.php')
-rwxr-xr-x | cgi/captcha.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/cgi/captcha.php b/cgi/captcha.php new file mode 100755 index 0000000..6881063 --- /dev/null +++ b/cgi/captcha.php @@ -0,0 +1,39 @@ +<?php + +use Gregwar\Captcha\CaptchaBuilder; + +const CAPTCHA_PHRASE_LENGTH = 7; + +require_once __DIR__ . "/../vendor/autoload.php"; + +session_start(); + +$mode = $_GET["m"] ?? "newcaptcha"; + +if ($mode === "newcaptcha") { + header("Pragma: no-cache"); + header("Cache-Control: no-cache"); + header("Location: ?m=captcha&r=" . urldecode(bin2hex(random_bytes(10)))); + exit; +} + +$charset = 'ABCDEFGHKLMNPQRTWXYZ234789abdefghkmnpqr'; +$phrase = ""; +for ($i = 0; $i < CAPTCHA_PHRASE_LENGTH; ++$i) + $phrase .= $charset[random_int(0, strlen($charset) - 1)]; + +$builder = new CaptchaBuilder($phrase); +$builder->setInterpolation(false); +$builder->build(256, 64); +$_SESSION["captcha_phrase"] = $builder->getPhrase(); + +if ($mode === "captcha") { + echo '<body background="?m=captchaimg&r=' . bin2hex(random_bytes(10)) . '">'; + exit; +} + +if ($mode === "captchaimg") { + header("Content-Type: image/jpeg"); + $builder->save(null, 40); + exit; +} |