api.php (1701B)
1 <?php 2 header("Cache-Control: no-cache, must-revalidate, no-store"); 3 ############################### 4 # include files from root dir # 5 ############################### 6 $root_1 = realpath($_SERVER["DOCUMENT_ROOT"]); 7 $currentdir = getcwd(); 8 $root_2 = str_replace($root_1, '', $currentdir); 9 $root_3 = explode("/", $root_2); 10 if ($root_3[1] == 'core') { 11 echo $root_3[1]; 12 $root = realpath($_SERVER["DOCUMENT_ROOT"]); 13 }else{ 14 $root = $root_1 . '/' . $root_3[1]; 15 } 16 $check = !file_exists($root . 'core/config/connect.db.inc.php'); 17 echo $check; 18 if (!file_exists('core/config/connect.db.inc.php')) { 19 header("HTTP/1.1 301 Moved Permanently"); 20 header("Location:install/index.php"); 21 }else{ 22 //$request = $_SERVER['REQUEST_URI']; 23 //$Api = substr($request, strrpos($request, 'v1/') + 3); 24 25 $scriptName = $_SERVER['SCRIPT_NAME']; 26 $requestUri = $_SERVER['REQUEST_URI']; 27 $queryString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; 28 29 // Physical path 30 if (strpos($requestUri, $scriptName) !== false) { 31 $physicalPath = $scriptName; // <-- Without rewriting 32 } else { 33 $physicalPath = str_replace('\\', '', dirname($scriptName)); // <-- With rewriting 34 } 35 36 $requestUri = $_SERVER['REQUEST_URI']; 37 $Api['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path 38 $Api['PATH_INFO'] = str_replace('?' . $queryString, '', $Api['PATH_INFO']); // <-- Remove query string 39 $Api['PATH_INFO'] = '/' . ltrim($Api['PATH_INFO'], '/'); // <-- Ensure leading slash 40 41 42 //header("HTTP/1.1 301 Moved Permanently"); 43 header("Location:/" . $root_3[1] . "/core/api/v1/api.php" . $Api['PATH_INFO']); 44 } 45 46 ?>