You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.2 KiB
PHP
32 lines
1.2 KiB
PHP
<?php
|
|
class Router {
|
|
public $returned = false;
|
|
|
|
function route($method, $url, $filename) {
|
|
$methods = ['GET', 'POST'];
|
|
if(in_array($method, $methods)) {
|
|
if($_SERVER['REQUEST_METHOD'] == $method) {
|
|
if ($_SERVER['REQUEST_URI'] == $url) {
|
|
require_once("./pages/$filename/$filename.php");
|
|
$this->returned = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function __destruct() {
|
|
if($_SERVER['REQUEST_METHOD'] == 'GET') {
|
|
if(!$this->returned){
|
|
$url = explode("/", $_SERVER['REQUEST_URI']);
|
|
$url = $url[count($url)-1];
|
|
|
|
if (file_exists("./pages/$url/$url.php")) {
|
|
require_once("./pages/$url/$url.php");
|
|
} else {
|
|
require_once("./pages/errors/404.php");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |