-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.php
More file actions
49 lines (42 loc) · 1.33 KB
/
demo.php
File metadata and controls
49 lines (42 loc) · 1.33 KB
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();
require_once 'captchaX.php';
$error = '';
$success = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$userInput = strtoupper(trim($_POST['captcha'] ?? ''));
$solution = $_SESSION['captcha_solution'] ?? '';
if ($userInput === $solution) {
$success = true;
unset($_SESSION['captcha_solution']);
} else {
$error = 'CAPTCHA verification failed. Please try again.';
}
}
// Generate new CAPTCHA for form
$captcha = captchaX\generate();
$_SESSION['captcha_solution'] = $captcha['captchaText'];
?>
<!DOCTYPE html>
<html>
<head>
<title>CAPTCHA Example</title>
</head>
<body>
<?php if ($success): ?>
<p style="color: green;">Form submitted successfully!</p>
<?php else: ?>
<form method="post">
<div>
<label>Enter the text shown in the image:</label><br>
<img src="pub/captchas/<?php echo $captcha['fileName']; ?>" alt="CAPTCHA"><br>
<input type="text" name="captcha" required>
</div>
<?php if ($error): ?>
<p style="color: red;"><?php echo $error; ?></p>
<?php endif; ?>
<button type="submit">Submit</button>
</form>
<?php endif; ?>
</body>
</html>