forked from aorti017/CS180-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.php
More file actions
38 lines (35 loc) · 1.09 KB
/
Copy pathnotifications.php
File metadata and controls
38 lines (35 loc) · 1.09 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
<?php
sleep(1);
session_start();
if(!isset($_COOKIE['username'])) {
header('Location: index.php');
}
setcookie('username', $_SESSION['username'], 0);
include './database.php';
$sender = $_GET['username'];
$lastTimeStamp = $_GET['time'];
while(true){
//$lastTimeStamp = (time()*1000);
$sqlStatement = "SELECT message, sender, timestamp FROM Messages WHERE receiver='".$sender."' and timestamp >= ".$lastTimeStamp." ORDER BY timestamp DESC";
//selects the most recent messages, ordered by timestamp
$results = executeStatement($sqlStatement);
$senderArray = array();
$messageArray = array();
$timeArray = array();
foreach($results as $row){
array_push($senderArray, $row["sender"]);
array_push($messageArray, $row["message"]);
array_push($timeArray, $row["timestamp"]);
}
$ret = array(
'message'=>$messageArray,
'sender'=>$senderArray,
'times'=>$timeArray,
'time'=>time()*1000
);
$json = json_encode($ret);
echo $json;
//sleep(1);
break;
}
?>