コード例 #1
0
ファイル: logout.php プロジェクト: sidewallme/Sample_projects
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");
コード例 #2
0
ファイル: logout.php プロジェクト: andreajeka/HKUST_Chatroom
}
// 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();