소스 검색

Some work done

AaronSpeer 7 년 전
부모
커밋
7dc9c9bfec
2개의 변경된 파일60개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      database.db
  2. 59 0
      index.php

+ 1 - 0
database.db

@@ -0,0 +1 @@
+{"test", "lol"},{"lol", "test"}

+ 59 - 0
index.php

@@ -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);
+}
+ ?>