1
0

Erster Commit

This commit is contained in:
Anna Christina Naß
2025-07-07 16:25:22 +02:00
parent 3b9e7bb194
commit ce5baaac35
23 changed files with 671 additions and 2 deletions

42
functions.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
/**
* An example CORS-compliant method. It will allow any GET, POST, or OPTIONS requests from any
* origin.
*
* In a production environment, you probably want to be more restrictive, but this gives you
* the general idea of what is involved. For the nitty-gritty low-down, read:
*
* - https://developer.mozilla.org/en/HTTP_access_control
* - https://fetch.spec.whatwg.org/#http-cors-protocol
*
*/
function cors() {
// Allow from any origin
header("Access-Control-Allow-Origin: *");
header('Access-Control-Max-Age: 86400'); // cache for 1 day
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Request-Headers: content-type");
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
// header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
// header("Access-Control-Request-Headers: content-type");
exit(0);
}
}
function return_success() {
return json_encode(['status' => 'success', 'message' => 'OK']);
}
function return_error($code, $msg) {
http_response_code($code);
return json_encode(['status' => 'error', 'message' => $msg]);
}
function twig_error($twig, $code, $msg) {
http_response_code($code);
return $twig->render('error.html.twig', [ 'error' => $msg ]);
}
?>