-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_chat.php
More file actions
114 lines (91 loc) · 3.15 KB
/
Copy pathstart_chat.php
File metadata and controls
114 lines (91 loc) · 3.15 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
<?php
error_reporting(0);
session_start();
require "config.php";
$to_id = $_GET["target"];
$from_id = $_SESSION["reg"];
$sql1 = "SELECT * FROM users where reg = $to_id;";
$q1 = mysqli_query($con, $sql1);
$r1 = mysqli_fetch_assoc($q1);
$status_sql = "SELECT status FROM status where reg = $to_id;";
$status_query = mysqli_query($con, $status_sql);
$status_check = mysqli_fetch_assoc($status_query);
$status_info = $status_check["status"];
#echo "Sender:$from_id and Receiver:$to_id";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="ex_css/start_chat3.css">
<script src="js/jquery.min.js"></script>
<title>Chats</title>
</head>
<body>
<div class="wrapper">
<div id="status" class="status-bar">
</div>
<div class='chat-field' style="height:500px;overflow-x:hidden;overflow-y:scroll;" id="chatbox">
</div>
<div class='text-sender'>
<textarea name="msg" id="msg"></textarea>
<input type="text" value="<?php echo $from_id ?>" id="from" hidden>
<input type="text" value="<?php echo $to_id ?>" id="to" hidden>
<button class='search-btn' id="send">Send</button>
</div>
</div>
<script>
var chatbox = document.getElementById('chatbox');
chatbox.scrollTop = chatbox.scrollHeight;
</script>
<script type="text/javascript">
var chatbox = document.getElementById('chatbox');
function scrollToBottom() {
chatbox.scrollTop = chatbox.scrollHeight;
}
$(document).ready(function () {
$("#send").click(function () {
$.ajax({
method: "POST",
url: "insertmsg.php",
data: {
from_id: $("#from").val(),
to_id: $("#to").val(),
msg: $("#msg").val(),
},
success: function (data) {
$("#msg").val("");
}
});
});
setInterval(function () {
$.ajax({
url: "allmsg.php",
method: "POST",
data: {
from_id: $("#from").val(),
to_id: $("#to").val(),
},
success: function (data) {
$("#chatbox").html(data);
scrollToBottom();
}
});
}, 700);
setInterval(function () {
$.ajax({
url: "status_check.php",
method: "POST",
data: {
to_id: $("#to").val(),
},
success: function (data) {
$("#status").html(data);
}
});
}, 700);
});
</script>
</body>
</html>