-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceive.php
37 lines (30 loc) · 950 Bytes
/
receive.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
<?php
$messageReceived = false;
$you = $_COOKIE['chat_you'];
$them = $_COOKIE['chat_them'];
if (mysql_connect("hostname","user","password"))
{
if (mysql_select_db("db"))
{
while ($messageReceived == false)
{
$query = "SELECT * FROM `messages` where `messageid` IN (SELECT MAX(`messageid`) FROM `messages` WHERE `read`=0 AND `recipient`='{$you}' AND `sender` = '{$them}' ORDER BY `messageid` DESC)";
$res = mysql_query($query);
if (mysql_num_rows($res) > 0)
{
$msg = mysql_fetch_array($res);
$jsonObj = Array(
'sender' => $msg['sender'],
'message' => $msg['message'],
'timestamp' => $msg['timestamp']
);
mysql_query("UPDATE `messages` SET `read`=1 WHERE `messageid`={$msg['messageid']}");
mysql_close();
$messageReceived = true;
echo json_encode($jsonObj);
}
sleep(1);
}
}
}
?>