|
@@ -0,0 +1,59 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+$error_reporting = 1; // 1 = errors 0 = none
|
|
|
+
|
|
|
+if ($error_reporting == 1){
|
|
|
+ ini_set('display_errors', 1);
|
|
|
+ ini_set('display_startup_errors', 1);
|
|
|
+ error_reporting(E_ALL);}
|
|
|
+
|
|
|
+//Make array $addr[] from url
|
|
|
+
|
|
|
+$basepath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/';
|
|
|
+$uri = substr($_SERVER['REQUEST_URI'], strlen($basepath));
|
|
|
+if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?'));
|
|
|
+$uri = '/' . trim($uri, '/');
|
|
|
+global $addr;
|
|
|
+$routes = array();
|
|
|
+$routes = explode('/', $uri);
|
|
|
+foreach($routes as $route)
|
|
|
+{
|
|
|
+ if(trim($route) != '')
|
|
|
+ array_push($routes, $route);
|
|
|
+ if ($route != ""){
|
|
|
+ $addr[] = $route;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+if ($addr[0]!="modify"){
|
|
|
+ render($addr);}
|
|
|
+else{
|
|
|
+ $db = json_decode(readDB(), true);
|
|
|
+ print_r($db);
|
|
|
+ //array_push($db, ["lol1", "test1"]);
|
|
|
+ echo json_encode($db);
|
|
|
+}
|
|
|
+
|
|
|
+function render($address){
|
|
|
+ $db = readDB();
|
|
|
+ $web = json_decode($db, true);
|
|
|
+ $route = implode(",", $address);
|
|
|
+ if (array_key_exists($route, $web)){
|
|
|
+ echo $web[$route];}
|
|
|
+ else {
|
|
|
+ echo "404";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function readDB(){
|
|
|
+ $myfile = fopen("database.db", "r");
|
|
|
+ return fread($myfile,filesize("database.db"));
|
|
|
+ fclose($myfile);
|
|
|
+}
|
|
|
+
|
|
|
+function writeDB($data){
|
|
|
+ $myfile = fopen("database.db", "w");
|
|
|
+ fwrite($myfile, $data);
|
|
|
+ fclose($myfile);
|
|
|
+}
|
|
|
+ ?>
|