-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloader.php
94 lines (63 loc) · 1.58 KB
/
loader.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
<?php
define ('HOME', dirname(__FILE__));
define ('SECRET_KEY','ashdj#');
require_once('includes/db.php');
require_once('includes/functions.php');
require_once('includes/routes.php');
error_reporting(E_ALL);
$siteUrl = $_SERVER['SERVER_NAME'];
$errors = 0;
$errorMessages = array();
$routeParams = [];
if(isset($_GET['_route']) && !empty($_GET['_route'])){
$route = rtrim($_GET['_route'],'/');
}else{
$route = 'index';
}
if(strpos($route,'/')){
$path = explode('/',$route);
}
//Prepare get
$getVariables = array();
unset($_GET['_route']);
foreach($_GET as $key => $value){
$getVariables[$key] = strip_tags($value);
}
//Prepare post
$postVariables = array();
foreach($_POST as $key => $value){
$postVariables[$key] = strip_tags($value);
}
if(is_dir('app/controllers/'.$route)){
$route = $route.'/index';
}
$_currentRoute = $route;
//Start the session
session_start();
//Sanitize the inputs
foreach($_GET as $key => $value){
$_GETRequest[$key] = htmlentities($value);
}
foreach($_POST as $key => $value){
$_POSTRequest[$key] = htmlentities($value);
}
//Create
$_done = 0;
//check in our routes table first
if($resolver = match_route($route,$_routes)){
$route = $resolver['route'];
$routeParams = $resolver['params'];
}
if(file_exists('app/controllers/'.$route.'.php')){
include('app/controllers/'.$route.'.php');
$_done = 1;
}
if(file_exists('app/views/'.$route.'.php')){
include('app/views/'.$route.'.php');
$_done = 1;
}
if($_done == 0){
//echo "resolver";
//print_r(match_route($route,$_routes));
die('ERROR: Cannot load controller or view :'.$route);
}