38 lines
No EOL
835 B
PHP
38 lines
No EOL
835 B
PHP
<?php
|
|
require_once(__DIR__."/jsonBuilder.inc.php");
|
|
|
|
function setDefaultHeader()
|
|
{
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
|
|
header("Access-Control-Allow-Headers: X-PINGOTHER, Content-Type");
|
|
header("Access-Control-Max-Age: 86400");
|
|
}
|
|
|
|
function respondJson(JsonBuilder $builder) {
|
|
setDefaultHeader();
|
|
header('Content-type: application/json');
|
|
echo($builder->getJson());
|
|
}
|
|
|
|
function respondHtml(string $html)
|
|
{
|
|
setDefaultHeader();
|
|
print($html);
|
|
}
|
|
|
|
function respondStatus(int $statusCode, string $message = "")
|
|
{
|
|
setDefaultHeader();
|
|
http_response_code($statusCode);
|
|
die($message);
|
|
}
|
|
|
|
function redirectBack() {
|
|
header("Location: {$_SERVER['HTTP_REFERER']}");
|
|
}
|
|
|
|
function redirectTo($url) {
|
|
header("Location: {$url}");
|
|
}
|
|
?>
|