-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
155 lines (149 loc) · 3.95 KB
/
index.php
File metadata and controls
155 lines (149 loc) · 3.95 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$message = $_POST['message'] ?? '';
if (!empty($message)) {
$file = fopen('kanta.txt', 'a');
fwrite($file, "$message\n");
fclose($file);
echo '<script>window.location.reload()</script>';
}
exit;
}
if (isset($_GET['latest_message'])) {
$messages = file('kanta.txt');
$latest_message = end($messages);
echo htmlentities($latest_message);
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>ChatGPT</title>
<style>
body {
background-color: #f1f1f1;
font-family: Arial, sans-serif;
}
.chat-box {
margin: 0 auto;
max-width: 600px;
background-color: #fff;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
border-radius: 5px;
overflow: hidden;
position: relative;
}
.chat-header {
background-color: #fff;
border-bottom: 1px solid #ddd;
padding: 10px 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
.chat-header h2 {
margin: 0;
font-size: 18px;
}
.chat-body {
height: 400px;
overflow-y: scroll;
padding: 10px;
}
.chat-message {
background-color: #f1f1f1;
padding: 10px;
border-radius: 5px;
margin-bottom: 10px;
}
.chat-message p {
margin: 0;
}
.chat-footer {
position: absolute;
bottom: 0;
width: 100%;
background-color: #f1f1f1;
padding: 10px;
display: flex;
}
.chat-input {
flex: 1;
margin-right: 10px;
padding: 10px;
border-radius: 5px;
border: none;
}
.chat-button {
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px;
cursor: pointer;
font-size: 16px;
}
.chat-button:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="chat-box">
<div class="chat-header">
<h2>ChatGPT</h2>
</div>
<div class="chat-body" id="chat-body">
<?php
if (file_exists('kanta.txt')) {
$messages = file('kanta.txt');
foreach ($messages as $message) {
echo '<div class="chat-message"><p>' . htmlentities($message) . '</p></div>';
}
}
?>
</div>
<div class="chat-footer">
<form method="post" id="chat-form" onsubmit="sendMessage(event)">
<input type="text" class="chat-input" name="message" placeholder="Type your message...">
<button type="submit" class="chat-button">Send</button>
</form>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Function to refresh messages
function refreshMessages() {
$.ajax({
url: "get_messages.php",
success: function(data) {
$(".chat-body").html(data);
// Scroll to bottom of chat body
var chatBody = document.querySelector('.chat-body');
chatBody.scrollTop = chatBody.scrollHeight;
}
});
}
// Refresh messages every 5 seconds
setInterval(refreshMessages, 5000);
// Submit form via AJAX
$("form").submit(function(event) {
event.preventDefault();
$.ajax({
url: "send_message.php",
type: "POST",
data: $(this).serialize(),
success: function() {
// Clear input field
$("input[name='message']").val("");
// Refresh messages
refreshMessages();
}
});
});
});
</script>
</html>