-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadjson.php
48 lines (38 loc) · 1.1 KB
/
readjson.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
41
42
43
44
45
46
47
48
<?php
if(!isset($_SERVER['HTTP_REFERER'])){
// redirect them to your desired location
header('location: index.php');
exit;
}
// read json file into array of strings
$jsonstring = file_get_contents("galleryinfo.json");
// save the json data as a PHP array
$phparray = json_decode($jsonstring, true);
// see results of decoded json into a php associative array
//echo "<pre>";
// var_dump($phparray);
// echo "</pre>";
// use GET to determine type of access
if (isset($_GET["access"])){
$access = $_GET["access"];
} else {
$access = "all";
}
// pull public or private only or return all
// NOTE: to make this more secure, if $access == "private" or "all"
// you would also check that an editor is logged in.
$returnData = [];
if ($access != "all") {
foreach($phparray as $entry) {
// var_dump($entry);
if ($entry["privacy"] == $access) {
$returnData[] = $entry;
}
} // foreach
} else {
$returnData = $phparray;
}
// encode the php array to json
$jsoncode = json_encode($returnData, JSON_PRETTY_PRINT);
echo ($jsoncode);
?>