48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
session_start();
|
|
|
|
$chat_history = [];
|
|
if (!empty($_SESSION['session_id'])) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT sender, message FROM chat_log WHERE session_id = ? ORDER BY created_at ASC");
|
|
$stmt->execute([$_SESSION['session_id']]);
|
|
$chat_history = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
// Not critical if history fails to load, so we just log it.
|
|
error_log("Could not load chat history: " . $e->getMessage());
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Chat with AI</title>
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<div class="chat-container">
|
|
<div class="chat-header">
|
|
<h2>AI Chat</h2>
|
|
</div>
|
|
<div class="chat-box" id="chat-box">
|
|
<!-- Chat messages will be appended here -->
|
|
</div>
|
|
<div class="chat-footer">
|
|
<form id="chat-form">
|
|
<input type="text" id="message-input" placeholder="Type your message..." autocomplete="off">
|
|
<button type="submit">Send</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const chatHistory = <?php echo json_encode($chat_history); ?>;
|
|
</script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</body>
|
|
</html>
|