header("Location: error.html");
    return;
}
// get the name from cookie
$name = $_COOKIE["name"];
$color = $_POST["color"];
// get the message content
$message = $_POST["message"];
if (trim($message) == "") {
    $message = "__EMPTY__";
}
require_once 'xmlHandler.php';
// create the chatroom xml file handler
$xmlh = new xmlHandler("chatroom.xml");
if (!$xmlh->fileExist()) {
    header("Location: error.html");
    exit;
}
// create the following DOM tree structure for a message and add it to the chatroom XML file
$xmlh->openFile();
// get the 'messages' element as the current element
$messages_element = $xmlh->getElement("messages");
// create a 'message' element for each message
$message_element = $xmlh->addElement($messages_element, "message");
// add the name
$xmlh->setAttribute($message_element, "name", $name);
$xmlh->setAttribute($message_element, "color", $color);
// add the content of the message
$xmlh->addText($message_element, $message);
$xmlh->saveFile();
header("Location: client.php");
Example #2
0
            echo "<font color='#FF0000'>error</font>";
            exit;
        } else {
        }
    }
}
if (empty($picName)) {
    $imgpath = "./image/auto.png";
} else {
    $imgpath = $picName;
}
require_once 'xmlHandler.php';
// create the chatroom xml file handler
$xmlh = new xmlHandler("chatroom.xml");
if (!$xmlh->fileExist()) {
    header("Location: error.html");
    exit;
}
$xmlh->openFile();
// get the 'users' element as the current element
$users_element = $xmlh->getElement("users");
// create a 'user' element for each user
$user_element = $xmlh->addElement($users_element, "user");
// add the name
$xmlh->setAttribute($user_element, "name", $_POST["name"]);
$xmlh->setAttribute($user_element, "pic", $imgpath);
$xmlh->saveFile();
// set the name to the cookie
setcookie("name", $_POST["name"]);
// Cookie done, redirect to client.php (to avoid reloading of page from the client)
header("Location: client.php");
Example #3
0
if (!isset($_POST["name"])) {
    header("Location: error.html");
    exit;
}
require_once 'xmlHandler.php';
// create the chatroom xml file handler
$xmlh = new xmlHandler("chatroom.xml");
if (!$xmlh->fileExist()) {
    header("Location: error.html");
    exit;
}
// open the existing XML file
$xmlh->openFile();
// get the 'users' element
$users_element = $xmlh->getElement("users");
// create a 'user' element
$user_element = $xmlh->addElement($users_element, "user");
// add the user name
$xmlh->setAttribute($user_element, "name", $_POST["name"]);
// Picture arrangements, move uploaded file to webserver
$pic_name = $_FILES["pic-upload"]["name"];
$pic_tmp = $_FILES["pic-upload"]["tmp_name"];
$pic_dir = "images/" . $pic_name;
move_uploaded_file($pic_tmp, $pic_dir);
// add the picture dir
$xmlh->setAttribute($user_element, "pic-upload", $pic_dir);
// save the XML file
$xmlh->saveFile();
setcookie("name", $_POST["name"]);
// Cookie done, redirect to client.php (to avoid reloading of page from the client)
header("Location: client.php");