-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample-form.php
More file actions
71 lines (63 loc) · 2.02 KB
/
Copy pathexample-form.php
File metadata and controls
71 lines (63 loc) · 2.02 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="Author" content="Jose Rodriguez"/>
<title>Captcha test</title>
<style type="text/css">
body {
font-family: sans-serif;
font-size: 0.8em;
padding: 20px;
}
#change-image {
font-size: 0.8em;
}
</style>
</head>
<body onload="document.getElementById('captcha-form').focus()">
<?php
/** Validate captcha */
if (!empty($_REQUEST['captcha'])) {
if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) {
$captcha_message = "Invalid captcha";
$style = "background-color: #FF606C";
} else {
$captcha_message = "Valid captcha";
$style = "background-color: #CCFF99";
}
$request_captcha = htmlspecialchars($_REQUEST['captcha']);
echo <<<HTML
<div id="result" style="$style">
<h2>$captcha_message</h2>
<table>
<tr>
<td>Session CAPTCHA:</td>
<td>{$_SESSION['captcha']}</td>
</tr>
<tr>
<td>Form CAPTCHA:</td>
<td>$request_captcha</td>
</tr>
</table>
</div>
HTML;
unset($_SESSION['captcha']);
}
?>
<p><strong>Write the following word:</strong></p>
<form method="GET">
<img src="cap.php" id="captcha"/><br/>
<!-- CHANGE TEXT LINK -->
<a href="#" onclick="
document.getElementById('captcha').src='captcha.php?'+Math.random();
document.getElementById('captcha-form').focus();"
id="change-image">Not readable? Change text.</a><br/><br/>
<input type="text" name="captcha" id="captcha-form"
autocomplete="off"/><br/>
<input type="submit"/>
</form>
</body>
</html>