-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
94 lines (75 loc) · 2.29 KB
/
index.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
84
85
86
87
88
89
90
91
92
93
94
<?php
if(isset($_GET) && isset($_GET['action']) && $_GET['action'] =='store') {
if(!isset($_POST['question']) || !isset($_POST['response']) || ($_POST['response'] != 'yes' && $_POST['response'] != 'no')) {
die("NO WAY");
} else {
$memcache_obj = memcache_connect('localhost', 11211);
$var = memcache_set($memcache_obj, md5(urldecode($_POST['question'])), $_POST['response'], 0, 60);
}
} elseif(isset($_GET) && isset($_GET['action']) && $_GET['action'] == 'get') {
if(!isset($_POST['question']) && !isset($_GET['question'])) {
die("NO WAY");
} else {
$q = isset($_POST['question']) ? urldecode($_POST['question']) : urldecode($_GET['question']);
$memcache_obj = memcache_connect('localhost', 11211);
$var = memcache_get($memcache_obj, md5($q));
if(!$var) {
sleep(3);
}
die($var);
}
}
?>
<html>
<body>
<title>The Question</title>
<link rel="stylesheet" href="style.css">
<?php
if((empty($_GET) || isset($_GET['q'])) && empty($_POST)) {
?>
<script type='text/javascript'>
window.addEventListener('load', function() {
var q = $('q');
q.innerText = $('question').value = GET('q') || 'Ask a question by using the q get parameter';
document.title += ' is: '+q.innerText;
});
function $(id) {
return document.getElementById(id);
}
function answerYes() {
$('response').value='yes';
$('f').submit();
}
function answerNo() {
$('response').value= 'no';
$('f').submit();
}
function GET( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var _GET = new RegExp("[\\?&]"+name+"=([^&#]*)" );
var results = _GET.exec( window.location.href );
return results == null ? null : decodeURIComponent(results[1]);
}
</script>
<div class='arrow_box'>
<h1 id='q'></h1>
<div class='buttons'>
<div class="button yes">
<a class="butt" onclick='answerYes()'>YES</a>
</div>
<div class="button no">
<a class="butt" onclick='answerNo()'>NO</a>
</div>
</div>
<form method='post' action='?action=store' id='f' style='display:none'>
<input type='hidden' name='question' value='' id='question'>
<input type='hidden' name='response' value='' id='response'>
</form>
<?php } else { ?>
<div class='arrow_box'>
<h1 id='q'>Thanks. You may now press back to close.</h1>
</div>
<? } ?>
<link href="http://fonts.googleapis.com/css?family=Terminal+Dosis:400,700" rel="stylesheet" type="text/css">
</html>