mirror of
https://github.com/neosubhamoy/neosubhamoy-portfolio.git
synced 2025-12-20 02:19:34 +05:30
(refactor): changed router file path (feat): added global host config
This commit is contained in:
43
htdocs/core/router.php
Normal file
43
htdocs/core/router.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
|
||||
|
||||
$serverRoutes = [
|
||||
'/' => 'home.php',
|
||||
'/projects' => 'projects.php',
|
||||
'/blog' => 'blog.php',
|
||||
'/contact' => 'contact.php',
|
||||
];
|
||||
|
||||
$devRoutes = [
|
||||
'/neosubhamoy/htdocs/' => 'home.php',
|
||||
'/neosubhamoy/htdocs/projects' => 'projects.php',
|
||||
'/neosubhamoy/htdocs/blog' => 'blog.php',
|
||||
'/neosubhamoy/htdocs/contact' => 'contact.php',
|
||||
];
|
||||
|
||||
if ($host == "localhost") {
|
||||
$routes = $devRoutes;
|
||||
}
|
||||
else {
|
||||
$routes = $serverRoutes;
|
||||
}
|
||||
|
||||
function routeTraffictToPages($uri, $routes) {
|
||||
if(array_key_exists($uri, $routes)) {
|
||||
require $routes[$uri];
|
||||
}
|
||||
else {
|
||||
error_page(404);
|
||||
}
|
||||
}
|
||||
|
||||
function error_page($status_code) {
|
||||
http_response_code($status_code);
|
||||
require "error/{$status_code}.php";
|
||||
die();
|
||||
}
|
||||
|
||||
routeTraffictToPages($uri, $routes);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user