This repository has been archived by the owner on Jul 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
81 lines (62 loc) · 2.08 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
<?php
require 'Slim/Slim.php';
require 'config.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->get('/', function(){
echo "<html><body><h1>We're counting...</h1></body></html>";
});
$app->get('/event/:code', function($code) use ($app) {
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
if ($mysqli->connect_errno) {
error_log("Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error);
$app->response->setStatus(500);
return;
}
/*
if (!($stmt = $mysqli->prepare('SELECT event_id FROM `events` WHERE CODE=? AND open<=CURDATE() AND close>=CURDATE()'))) {
error_log("Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error);
$app->response->setStatus(500);
return;
}
if (!$stmt->bind_param("s", $code)) {
error_log("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error);
$app->response->setStatus(500);
return;
}
if (!$stmt->execute()) {
error_log("Execute failed: (" . $stmt->errno . ") " . $stmt->error);
$app->response->setStatus(500);
return;
}
if(!$stmt->bind_result($eventID)){
error_log("Bind Result failed: (" . $stmt->errno . ") " . $stmt->error);
$app->response->setStatus(500);
return;
}
$stmt->fetch();
$stmt->close();
echo "EventID:".$eventID;
*/
//workaround for query
switch ($code) {
case "gi2015":
$eventID = 1;
break;
case "gi2015a":
$eventID = 2;
break;
case "gi2015b":
$eventID = 3;
break;
}
$ip = $app->request->headers->get('x-forwarded-for');
if(!$mysqli->query("INSERT INTO `clicks` (`event_id`, `ip_address`) VALUES (".$eventID.", INET_ATON('".$ip."'))")) {
error_log("Insert Query failed: (" . $mysqli->errno . ") " . $mysqli->error);
$app->response->setStatus(500);
return;
}
$mysqli->close();
$app->render($code.".html");
});
$app->run();