您最多能選擇 25 個主題 主題必須以字母或數字為開頭,可包含連接號「-」且最長為 35 個字元。

66 行
1.5 KiB
PHP

<?php
/**
* This file contains global settings and things that should be loaded at the
* top of each file.
*/
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json; charset=utf-8');
// Composer
require 'vendor/autoload.php';
// API response formatters
require 'response.php';
// Settings file
require 'settings.php';
// Init database and stuff
$database;
try {
$database = new medoo([
'database_type' => DB_TYPE,
'database_name' => DB_NAME,
'server' => DB_SERVER,
'username' => DB_USER,
'password' => DB_PASS,
'charset' => DB_CHARSET
]);
} catch (Exception $ex) {
header('HTTP/1.1 500 Internal Server Error');
sendError('Database error. Try again later.', true);
}
if (!DEBUG) {
error_reporting(0);
} else {
error_reporting(E_ALL);
ini_set('display_errors', 'On');
}
$VARS;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$VARS = $_POST;
define("GET", false);
} else {
$VARS = $_GET;
define("GET", true);
}
/**
* Checks if a string or whatever is empty.
* @param $str The thingy to check
* @return boolean True if it's empty or whatever.
*/
function is_empty($str) {
return (!isset($str) || $str == '' || $str == null);
}
if (is_empty($VARS['key'])) {
sendError('Please supply an API key (?key=abc)', true);
}
if (!$database->has('apikeys', ["AND" => ['apikey' => $VARS['key'], "active" => 1]])) {
sendError('Invalid or inactive API key.', true);
}