diff options
Diffstat (limited to 'help3/xhpeditor/api/helpers.php')
-rw-r--r-- | help3/xhpeditor/api/helpers.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/help3/xhpeditor/api/helpers.php b/help3/xhpeditor/api/helpers.php new file mode 100644 index 00000000..523f1012 --- /dev/null +++ b/help3/xhpeditor/api/helpers.php @@ -0,0 +1,27 @@ +<?php + +function get_method() { + return $_SERVER["REQUEST_METHOD"]; +} + +function get_data() { + return array_merge( + $_GET, + empty($_POST) ? [] : $_POST, + (array) json_decode(file_get_contents('php://input'), true) + ); +} + + +function respond($response, $code=200) { + http_response_code($code); + header('Content-Type: application/json'); + die(json_encode($response)); +} + +function is_not_ajax () { + return ( + empty($_SERVER['HTTP_X_REQUESTED_WITH']) + || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest' + ); +} |