<?php
header('Content-Type: application/json');
require_once dirname(__FILE__) . '/../../config.php';
$db = getDB();

$token = 'e5949d81a15a39fecc5b992e4';

// Buscar el token (parcial) en la BD
$stmt = $db->prepare("SELECT token, expira, NOW() as ahora FROM admin_sessions WHERE token LIKE ? LIMIT 3");
$stmt->execute([$token . '%']);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

// También ver todos los tokens activos
$stmt2 = $db->query("SELECT LEFT(token,20) as token_short, expira, NOW() as ahora, (expira > NOW()) as valido FROM admin_sessions ORDER BY expira DESC LIMIT 5");
$activos = $stmt2->fetchAll(PDO::FETCH_ASSOC);

echo json_encode(['token_buscado' => $rows, 'ultimos' => $activos], JSON_PRETTY_PRINT);
