-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.php
40 lines (34 loc) · 1.26 KB
/
control.php
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
<?php
function path($path){
if($path === "/"){
include ("index.html");
}elseif($path === "/facts"){
$json_data = file_get_contents("data/data.json");
$data = json_decode($json_data, true);
header('content-type: application/json');
return json_encode($data);
}elseif(str_starts_with($path, "/facts/dogs")){
// Fetch JSON from thee file
$json_data = file_get_contents("data/dogfacts.json");
$data = json_decode($json_data, true);
// To check if theres an extra parameter for number of data to send
$num = substr($path, 12);
$response = [];
if($num > 0){
for ($i = 0; $i < $num; $i++){
$response[] = $data[rand(0, 200)];
}
}else{
$response[] = $data[rand(0, 200)];
}
header("content-type: application/json");
return json_encode($response, true);
}elseif($path === "/ceevee"){
header('Content-type: application/docx');
return readfile("CavemanResume.docx");
}else{
include "404.html";
}
}
echo path($_SERVER["REQUEST_URI"]);
?>