TKK_E32230273/generate_finger_token_accou...

37 lines
1.1 KiB
PHP

<?php
include 'koneksi.php';
header('Content-Type: application/json');
if (!isset($_GET['id'])) {
echo json_encode(["status" => "error", "message" => "ID tidak valid"]);
exit;
}
$id = $_GET['id'];
try {
$stmt = $pdo->prepare("SELECT code_register FROM account WHERE id_account = ?");
$stmt->execute([$id]);
$code = $stmt->fetchColumn();
if (!$code) {
$code = sprintf("%06d", mt_rand(1, 999999));
$update = $pdo->prepare("UPDATE account SET code_register = ? WHERE id_account = ?");
$update->execute([$code, $id]);
}
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
$host = $_SERVER['HTTP_HOST'];
// Sesuaikan request URI path ke depan instalasi (skydash)
$uriPath = dirname($_SERVER['REQUEST_URI']);
if($uriPath == '/' || $uriPath == '\\') $uriPath = '';
// URL scan_here.php
$url = $protocol . "://" . $host . $uriPath . "/scan_here.php?token=" . $code;
echo json_encode(["status" => "success", "url" => $url, "code" => $code]);
} catch (Exception $e) {
echo json_encode(["status" => "error", "message" => $e->getMessage()]);
}
?>