<?php
ini_set('display_errors', 1);
date_default_timezone_set('Asia/Kolkata');
require_once '/home/rejoicebilldesk/public_html/rjllearning_development/resources/base_path_include.php';

require_once $base_path_to_learning_resources  . "includes/connect.php"; // use require for mandatory files
require_once $base_path_to_learning_resources . 'lib/function.php';


/**
 * Deletes expired OTPs (older than 15 minutes) from otp_store table.
 * @param PDO $conn The database connection instance.
 */
function deleteExpiredOTPs($conn) {
    try {
        $delete_query = "DELETE FROM otp_store WHERE timestamp < ?";
        $stmt = $conn->prepare($delete_query);
        $stmt->execute([time() - 900]); // 900 seconds = 15 minutes

        // Optional: Log the number of rows deleted (for debugging)
        $deletedRows = $stmt->rowCount();
        // error_log("Deleted $deletedRows expired OTPs.");
    } catch (PDOException $e) {
        error_log("Error deleting expired OTPs: " . $e->getMessage());
    }
}

// Call function
deleteExpiredOTPs($conn_rjllearning);



