Примитивный роутер для процедурного приложения

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
if (isset($_GET['url'])) {
$url = trim($_GET['url'], '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
$app = (isset($url[0]) ? $url[0] : 'index');
$one = (isset($url[1]) ? $url[1] : null);
$two = (isset($url[2]) ? $url[2] : null);
$three = (isset($url[3]) ? $url[3] : null);
$app_file = APP.'/'.strtolower($app).'.php';
if(file_exists($app_file)) {
require_once $app_file;
} else {
require_once APP.'/notfound.php';
}
} else { require_once APP.'/index.php'; }