123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?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);
- $db["lol2"] = "test2";
- writeDB(json_encode($db));
- }
- function render($address){
- $db = readDB();
- echo $db;
- $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);
- }
- ?>
|