<title>User List</title>
	<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
	<table border="1" cellspacing="0" cellpadding="5" align="left">
		<tr bgcolor="#ffffff">
			<th>UserPic</th>
			<th>UserName</th>
		</tr>
		<?php 
if ($users_array != null) {
    foreach ($users_array as $user) {
        ?>
		<tr style="border-top: 1px solid gray" align="left">
		<td><img src="<?php 
        echo $xmlh->getAttribute($user, "pic");
        ?>
" alt="<?php 
        echo $xmlh->getAttribute($user, "name");
        ?>
" width="50" height="50"></td>
		<td><?php 
        echo $xmlh->getAttribute($user, "name");
        ?>
</td>
		</tr>
		<?php 
    }
}
?>
	</table>
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 the name from the cookie
$name = $_COOKIE["name"];
$xmlh->openFile();
// get the users element
$users_node = $xmlh->getElement("users");
// get all user nodes
$users_array = $xmlh->getChildNodes("user");
if ($users_array != null) {
    // delete the current user from the users element
    foreach ($users_array as $user) {
        $username = $xmlh->getAttribute($user, "name");
        if ($username == $name) {
            $xmlh->removeElement($users_node, $user);
        }
    }
}
$xmlh->saveFile();
// clear the cookie
setcookie("name", "");
header("Location: login.html");
Exemple #3
0
    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");