adlerka.top/lib/router.php
2024-02-06 16:28:36 +01:00

38 lines
938 B
PHP

<?php
function initRouter(): array
{
global $routerConfig;
$routerRequest = array();
$routerRequest["requestAddress"] = array_slice(explode('.', $_SERVER['HTTP_HOST']), -3, 3); //get the last 3 elements
$request_uri = explode("/", $_SERVER["QUERY_STRING"]);
$request_uri = array_slice($request_uri, -3, 3);
print_r($request_uri);
$routerRequest["site_name"] = basename($request_uri[1]);
$routerRequest["page_name"] = basename($request_uri[2]);
if (empty($routerRequest["site_name"])) {
$routerRequest["site_name"] = $routerConfig["default_site"];
}
if (empty($routerRequest["page_name"])) {
$routerRequest["page_name"] = $routerConfig["default_page"];
}
if($_SERVER["REQUEST_METHOD"] == "POST"){
$routerRequest["type"] = "api";
}
if(empty($routerRequest["type"])) {
$routerRequest["type"] = "page";
}
return $routerRequest;
}