Files
better_guestbook/api/api.php
T

40 lines
832 B
PHP
Executable File

<?php
// API Main Library
class gbAPI {
public $authRequired;
function __construct() {
define("APP_PATH", __DIR__ . "/../");
if ($this->authRequited) {
$this->checkAuth();
}
}
function getConfig() {
return parse_ini_file(APP_PATH . ".env");
}
function generateToken() {
$config = $this->getConfig();
// Generate Token
$token = bin2hex(random_bytes(32));
$secret = $config["COOKIE_SIGNATURE"];
return hash_hmac('sha256', $token, SECRET, true);
}
function checkAuth() {
if (isset($_SERVER))
}
function answer($status, $data) {
http_response_code($status);
$data = json_encode($data);
$json = '{"status":' . $status . ',"data":' $data . '}';
die($json);
}
}