-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
83 lines (60 loc) · 1.73 KB
/
test.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
// /public_html/test.php
// /verify/
$dir = "../verify/";
$json = json_decode(file_get_contents( $dir . "mapping.json") , true);
$c = count($json) - 1;
function image($loc)
{
return base64_encode(file_get_contents($loc));
}
session_start();
if ($_POST["submit"])
{
if ($_POST["code"] == $_SESSION['code'])
{
$recipient = "[email protected]"; // receiver's email
$subject = "Email Subject";
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$title = $_POST["subject"];
$mailBody = "Name: $name\nEmail: $email\n$title\n\n$message";
mail($recipient, $subject, $mailBody, "From: $name <$email>");
echo '<script>alert("Thank you for you feedback")</script>';
}
else
{
echo '<script>alert("Wrong code")</script>';
}
}
$rand = rand(0, $c); // generate random number
$code = $json[$rand]; // get object
foreach ($code as $k => $v)
{
$image = $dir . $k . ".jpg";
}
$_SESSION['code'] = $v; // save the code value to session
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Image Captcha</title>
</head>
<body>
<form method="POST">
<label>Name</label><br>
<input type="text" name="name" required/><br><br>
<label>Email</label><br>
<input type="text" name="email" required/><br><br>
<label>Subject</label><br>
<input type="text" name="subject" required/><br><br>
<label>Message</label><br>
<input type="text" name="message" required/><br><br>
<label>Enter Code</label><br>
<img src='data:image/png;base64,<?= image($image); ?>' height="100px" alt="code"><br>
<input type="number" name="code" required/><br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>