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");
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");
<?php require_once 'xmlHandler.php'; $datasize = $_POST["datasize"]; // set the execution time limit for this php session to 60 seconds (default is in php.ini) set_time_limit(60); // create the chatroom xml file handler $xmlh = new xmlHandler("chatroom.xml"); // check if the chatroom XML data file exists if (!$xmlh->fileExist()) { // create new XML file $xmlh->openFile(); // create a 'chatroom' element, as root element $root = $xmlh->addRootElement("chatroom"); // create a 'messages' element for the set of messages $xmlh->addElement($root, "users"); $xmlh->addElement($root, "messages"); // save the XML file $xmlh->saveFile(); } $start = gettimeofday(); while (1) { // if the file size of chatroom.xml is changed, that means new message has been added if ($xmlh->fileExist()) { // if data size is changed, // stop running this while loop to send messages to user if ($_POST["datasize"] != filesize("chatroom.xml")) { break; } } // clear the internal cache of file system functions from php