-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·55 lines (46 loc) · 1.63 KB
/
Copy pathindex.php
File metadata and controls
executable file
·55 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
ob_start();
$microtime=microtime(true);
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');
include 'includes.php';
//make path an array
$return = ['message'=>'', 'warning'=>'', 'debug'=>[], 'data'=>[], 'log'=>[] ];
$path = $_SERVER['REQUEST_URI'];
$path = explode( '?', $path)[0]; //omit GET parameters
$path = explode( '//', $path); //get parameters after the "//"
if (isset ($path[1])){ //if there are any parameters ...
$paras = explode('/', $path[1]); //...transform them to an array...
}
else{
$paras = []; //...or else just set an empty array
}
$path = $path[0];
$path = substr($path, strlen(PATH)+1);
// Fallback for servers that collapse "//" to "/" so routes like product//id still work.
if (!count($paras) && strpos($path, '/') !== false) {
if (!file_exists('routes/'.$path.'.php')) {
$path_parts = explode('/', $path);
if (count($path_parts) > 1 && file_exists('routes/'.$path_parts[0].'.php')) {
$path = array_shift($path_parts);
$paras = $path_parts;
}
}
}
$method = $_SERVER['REQUEST_METHOD'];
if (DEBUG)
{
$return['log']['method'] = $method;
$return['log']['input'] = file_get_contents("php://input");
}
$user = get_user();
$data = json_decode(file_get_contents("php://input"), TRUE);
// is_dir ( string $filename ) : bool — Prüft, ob der angegebene Dateiname ein Verzeichnis ist
// file_exists ( string $filename ) : bool
// Check file, check folder, Pass rest to function
include_once 'routes/'.$path.'.php';
terminate();
?>