-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequests.php
47 lines (45 loc) · 1.32 KB
/
requests.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
<?php
function GET($param, $switchlike = false, $required = false) {
$value = null;
if (isset($_GET[$param])) {
$value = $_GET[$param];
if ($switchlike && in_array(strtolower($value), ["1", "on", "true", ""])) {
return true;
}
if ($required && trim($value) == "") {
die(json_encode(["error" => "Missing parameter value: {$param}"]));
}
return $value;
}
if ($required) {
die(json_encode(["error" => "Missing parameter: {$param}"]));
}
return null;
}
function POST($param, $switchlike = false, $required = false) {
$value = null;
if (isset($_POST[$param])) {
$value = $_POST[$param];
}
else if (isset($_FILES[$param])) {
$value = $_FILES[$param];
}
if ($value) {
if (is_string($value)) {
if ($switchlike && in_array(strtolower($value), ["1", "on", "true", ""])) {
return true;
}
if ($required && trim($value) == "") {
die(json_encode(["error" => "Missing parameter value: {$param}"]));
}
return $value;
}
if (is_array($value)) {
return $value;
}
}
if ($required) {
die(json_encode(["error" => "Missing parameter: {$param}"]));
}
return null;
}