-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.php
60 lines (57 loc) · 1.25 KB
/
index.php
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
<?php
include_once 'php-db.php';
$result = $mysqli -> query('
SELECT * FROM (
SELECT name, message, time FROM chat_messages ORDER BY time DESC LIMIT 20
) tmp ORDER BY time ASC
');
?>
<!DOCTYPE html>
<html>
<head>
<title>Chat App by Hyvor Developer</title>
<style type="text/css">
* {
box-sizing:border-box;
}
#content {
width:600px;
max-width:100%;
margin:30px auto;
background-color:#fafafa;
padding:20px;
}
#message-box {
min-height:400px;
overflow:auto;
}
.author {
margin-right:5px;
font-weight:600;
}
.text-box {
width:100%;
border:1px solid #eee;
padding:10px;
margin-bottom:10px;
}
</style>
</head>
<body>
<div id="content">
<div id="message-box">
<?php foreach ($result as $row) : ?>
<div>
<span class="author"><?= $row['name'] ?>:</span>
<span class="messsage-text"><?= $row['message'] ?></span>
</div>
<?php endforeach; ?>
</div>
<div id="connecting">Connecting to web sockets server...</div>
<input type="text" class="text-box" id="name-input" placeholder="Your Name">
<input type="text" class="text-box" id="message-input" placeholder="Your Message" onkeyup="handleKeyUp(event)">
<p>Press enter to send message</p>
</div>
<script type="text/javascript" src="js-index.js"></script>
</body>
</html>