-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
70 lines (56 loc) · 1.55 KB
/
helper.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
function getDbConnection() {
$servername = 'fabigler.mysql.db.internal';
$username = 'fabigler_fabian';
$password = 'yeUt39N2';
$dbname = 'fabigler_bmoebel';
$con = new mysqli($servername, $username, $password, $dbname);
if (mysqli_connect_errno()) {
die("Connection failed: " . $con->connect_error);
}
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
return $con;
}
function getJsonInput() {
return json_decode(file_get_contents("php://input"), true);
}
function getStringFromUrl($name) {
return htmlspecialchars($_GET[$name]);
}
function getLangFromCookie() {
if (isset($_COOKIE["currentLang"])) {
return htmlspecialchars($_COOKIE["currentLang"]);
}
else {
return 'DE';
}
}
function setJsonResponse($result) {
header("Content-Type: application/json; charset=UTF-8;");
echo json_encode($result);
}
function setNotFoundResponse() {
http_response_code(404);
exit();
}
function setForbiddenResponse() {
setErrorResponse(null, "Forbidden!", 403);
}
function setErrorResponse($errorDetails, $errorMessage = "An error occured!", $httpErrorCode = 500) {
$error = new stdClass;
$error->errorMessage = $errorMessage;
$error->errorDetails = $errorDetails;
setJsonResponse($error);
http_response_code($httpErrorCode);
exit();
}
function setFatalErrorResponse() {
$lastError = error_get_last();
if ($lastError !== null) {
ob_clean();
setErrorResponse($lastError);
}
}
?>