/
logout.php
54 lines (41 loc) · 1.22 KB
/
logout.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
<?php
require_once('xmlHandler.php');
if (!isset($_COOKIE["name"])) {
header("Location: error.html");
exit;
}
// create the chatroom xml file handler
$xmlh = new xmlHandler("chatroom.xml");
if (!$xmlh->fileExist()) {
header("Location: error.html");
exit;
}
// get user name from cookie
$name = $_COOKIE["name"];
print($name);
// open the existing XML file
$xmlh->openFile();
// get the 'users' element
$users_element = $xmlh->getElement("users");
// get all 'user' nodes
$user_element = $xmlh->getChildNodes("user");
if($user_element != null) {
// delete the current user from the users element
foreach ($user_element as $user) {
$username = $xmlh->getAttribute($user, "name");
if ($username == $name) {
// Remove picture from our images folder
$uploadpic = $xmlh->getAttribute($user, "pic-upload");
unlink($uploadpic);
// Remove the user element completely
$xmlh->removeElement($users_element, $user);
}
}
}
// save the XML file
$xmlh->saveFile();
// set the name to the cookie
setcookie("name","");
// Cookie done, redirect to client.php (to avoid reloading of page from the client)
header("Location: login.html");
?>