-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.php
44 lines (37 loc) · 1000 Bytes
/
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
<?php
require_once 'includes/core.php';
if(isset($_GET['route'])) {
$route = $_GET['route'];
} else {
$route = 'home/index';
}
$security = new CSRF;
$token = $security->set(3, 3600);
$routeParts = explode('/', $route);
$controller = ucfirst($routeParts[0]) . 'Controller';
$method = ucfirst($routeParts[1]);
if(count($routeParts) == 1) {
header("Location: index.php?route=" . $routeParts[0] . '/home');
exit();
}
$reqMethod = 'get';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['token'])) {
if($security->get($token)) {
$security->delete($token);
$reqMethod = 'post';
}
}
}
$smarty->assign('csrf_field', '<input type="hidden" name="token" value="' . $security->set(3, 3600) . '" />');
$method = $reqMethod . $method;
if(class_exists($controller)) {
$controller = new $controller($smarty, $security, $db, $controller . '.' . $method);
if(method_exists($controller, $method)) {
print $controller->$method();
} else {
echo 404;
}
} else {
echo 404;
}