-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_endpoint.php
More file actions
51 lines (41 loc) · 1.38 KB
/
get_endpoint.php
File metadata and controls
51 lines (41 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
include './session_time_controller.php';
if (!isset($_SESSION['api_creator_user_session']) && $_SESSION['api_creator_user_session'] != "OK") {
echo json_encode(["status" => "error", "message" => "Sesión expirada."]);
exit();
}
// Creamos la Base de datos de API Creator, si no existe, y controlamos login
require_once "./connection.php";
$pdoApiCreator = getDatabaseConnection($databaseFile);
// Leer ID del POST
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id <= 0) {
echo json_encode(["status" => "error", "message" => "ID inválido."]);
exit;
}
// Consultamos los datos del endpoint
$registro = [];
try {
// Preparar la consulta
$stmt = $pdoApiCreator->prepare("SELECT * FROM endpoints WHERE id = :id");
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
// Obtener el resultado
$registro = $stmt->fetch(PDO::FETCH_ASSOC);
closeStmt($stmt);
if(!isset($registro['return_text'])) {
$registro['return_text'] = "";
}
if (!$registro) {
echo json_encode(['success' => false, 'error' => 'No encontrado']);
exit;
}
} catch (PDOException $e) {
closeStmt($stmt);
echo json_encode(['success' => false, 'error' => "Error al recuperar el registro $id"]);
exit;
}
closeStmt($stmt);
closeConnection($pdoApiCreator);
echo json_encode(['success' => true, 'endpoint' => $registro]);
?>