-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinbox.php
61 lines (48 loc) · 1.58 KB
/
inbox.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
61
<?php
include_once("secHelper.php");
echo "<html
<head>
<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js\"></script>
<title>Matt and Lee's Project 5</title>
</head>
<body>
<h1> Inbox </h1>
";
session_start();
if(isset($_SESSION["user"])){?>
<div id="messages">
<?php
$myfile = @fopen("users.txt", "r") or die("Unable to open file!");
while (($line = @fgets($myfile)) !== false) {
$userInfo = explode(":", $line);
if($userInfo[0] == $_SESSION["user"]){
$key = $userInfo[3];
}
}
$json = file_get_contents("messages.txt");
$json = str_replace('},]', "}]", $json);
$data = json_decode($json, true);
$str = "<table border=2>";
$str .= "<tr>";
$str .= "<td>From</td><td>Message</td>";
$str .= "</tr>";
if(isset($data)){
foreach ($data as $message){
if($message["To"] == $_SESSION["user"]){
$str .= "<tr>";
$str .= "<td>".$message["From"]."</td>";
$str .= "<td>".rsa_decrypt(utf8_decode($message["Body"]), $key)."</td>";
$str .= "</tr>";
}
}
}
$str .= "</table>";
echo $str;
?>
</div>
<br>
<a href="/se319lab5/viewPosts.php"><input type="button" value="Posts"></a>
<?php }else{?>
<p>You are not logged in!</p>
<?php }?>
<?php echo " </body> <script src=\"actions.js\"></script> </html>";?>