Files
2026-09-16 23:20:08 +07:00

25 lines
716 B
PHP

<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
require_once __DIR__ . '/db.php';
function logActivity($action, $table_name = null, $record_id = null) {
global $pdo;
$user_id = $_SESSION['user_id'] ?? null;
$ip_address = $_SERVER['REMOTE_ADDR'] ?? null;
if ($ip_address === '::1') {
$ip_address = '127.0.0.1';
}
try {
$stmt = $pdo->prepare("INSERT INTO activity_logs (user_id, action, table_name, record_id, ip_address) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$user_id, $action, $table_name, $record_id, $ip_address]);
} catch (PDOException $e) {
error_log("Failed to log activity: " . $e->getMessage());
}
}
?>