date('Y-m-d H:i:s'), 'action' => '管理员登录', 'ip' => $_SERVER['REMOTE_ADDR'] ]; // 保存登录日志 saveLog($log_entry); // 跳转到管理页面 header('Location: admin.php'); exit; } else { // 登录失败 $error = '密码错误,请重试'; } } // 保存日志函数 function saveLog($log_entry) { $log_file = 'data/operation_log.json'; // 检查目录是否存在,不存在则创建 if (!file_exists(dirname($log_file))) { mkdir(dirname($log_file), 0777, true); } // 读取现有日志 $logs = []; if (file_exists($log_file)) { $content = file_get_contents($log_file); if (!empty($content)) { $logs = json_decode($content, true); } } // 添加新日志 array_unshift($logs, $log_entry); // 限制日志数量,只保留最新的500条 if (count($logs) > 500) { $logs = array_slice($logs, 0, 500); } // 保存日志 file_put_contents($log_file, json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); } ?> 🚀 基金监控 - 登录