Initial commit: 교육 프로젝트 배포
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../db_conn.php';
|
||||
|
||||
$memberId = (string)($_SESSION['member_id'] ?? '');
|
||||
if ($memberId === '') {
|
||||
http_response_code(401);
|
||||
echo json_encode(['success' => false, 'message' => 'not_logged_in'], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$code = strtoupper(trim((string)($_GET['code'] ?? '')));
|
||||
$code = preg_replace('/[^A-Z0-9]/', '', $code);
|
||||
if ($code === '') {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'code_required'], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = db_conn();
|
||||
$stmt = $pdo->prepare('SELECT code_name FROM edu_codes WHERE REPLACE(REPLACE(UPPER(base_code), "-", ""), " ", "") = ? LIMIT 1');
|
||||
$stmt->execute([$code]);
|
||||
$codeName = (string)($stmt->fetchColumn() ?: '');
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'code' => $code,
|
||||
'code_name' => $codeName,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP);
|
||||
} catch (Throwable $e) {
|
||||
error_log('[code_name] ' . $e->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'server_error'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Reference in New Issue
Block a user