addGlobal('session', $_SESSION); return $twig->load($view_name . '.html.twig'); } catch (Exception $e) { die ('ERROR: ' . $e->getMessage()); } } $dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) { $r->addRoute('GET', '/', 'signin'); $r->addRoute('POST', '/auth', 'auth'); $r->addRoute('GET', '/home', 'home'); $r->addRoute('GET', '/changepassword', 'form_password'); $r->addRoute('POST', '/changepassword', 'change_password'); $r->addRoute('GET', '/signout', 'signout'); $r->addRoute('GET', '/ssh', 'form_ssh'); $r->addRoute('GET', '/getsshkeys', 'get_ssh_keys'); $r->addRoute('POST', '/addsshkey', 'add_ssh_key'); $r->addRoute('POST', '/delsshkey', 'del_ssh_key'); }); // Fetch method and URI from somewhere $httpMethod = $_SERVER['REQUEST_METHOD']; $uri = $_SERVER['REQUEST_URI']; // Strip query string (?foo=bar) and decode URI if (false !== $pos = strpos($uri, '?')) { $uri = substr($uri, 0, $pos); } $uri = rawurldecode($uri); $routeInfo = $dispatcher->dispatch($httpMethod, $uri); switch ($routeInfo[0]) { case FastRoute\Dispatcher::NOT_FOUND: // ... 404 Not Found break; case FastRoute\Dispatcher::METHOD_NOT_ALLOWED: $allowedMethods = $routeInfo[1]; // ... 405 Method Not Allowed break; case FastRoute\Dispatcher::FOUND: $handler = $routeInfo[1]; $handler(); break; }