-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting.php
54 lines (43 loc) · 1.36 KB
/
setting.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
49
50
51
52
53
54
<?php
//---------------------------------
// Author: Genie Jhang
// e-mail: geniejhang@majimak.com
// Date: 2014. 11. 6
//---------------------------------
$filename = 'settings.json';
$settingsText = file_get_contents($filename);
$settings = json_decode($settingsText, true);
if (isset($_GET['read'])) {
$readItem = $_GET['read'];
$exist = array_key_exists($readItem, $settings);
if ($exist)
echo $settings[$readItem];
}
if (isset($_GET['write'])) {
$writeItem = $_GET['write'];
$value = $_GET['value'];
$exist = array_key_exists($writeItem, $settings);
if ($exist)
$settings[$writeItem] = $value;
$settingsFile = fopen($filename, 'w+') or die("Unable to open file!");
fwrite($settingsFile, json_encode($settings));
fclose($settingsFile);
}
function readSetting($item) {
$filename = 'settings.json';
$settingsText = file_get_contents($filename);
$settings = json_decode($settingsText, true);
return $settings[$item];
}
function writeSetting($item, $value) {
$filename = 'settings.json';
$settingsText = file_get_contents($filename);
$settings = json_decode($settingsText, true);
$exist = array_key_exists($writeItem, $settings);
if ($exist)
$settings[$writeItem] = $value;
$settingsFile = fopen($filename, 'w+') or die("Unable to open file!");
fwrite($settingsFile, json_encode($settings));
fclose($settingsFile);
}
?>