forked from Adleraci/adlerka.top
		
	
		
			
				
	
	
		
			39 lines
		
	
	
		
			965 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			965 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"]);
 | 
						|
 | 
						|
    print_r($request_uri);
 | 
						|
    $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;
 | 
						|
}
 | 
						|
 | 
						|
 |