📄 login.php
字号:
<?php
require_once('xmlHandler.php');
$fn_xml = "chatroom.xml";
// Check that if name (form input) is in the post data, set it in the session cookie
if (isset($_POST["name"])) {
setcookie("name", $_POST["name"]);
// create the chatroom xml file handler
$xmlh = new xmlHandler($fn_xml);
if (!$xmlh->fileExist()) {
header("Location: error.html");
exit;
}
// open the existing XML file
$xmlh->openFile();
// get all the child nodes of the the 'users' element
$users_array = $xmlh->getChildNodes("user");
// check if the ms agent is selected by other users
if ($users_array!=null) {
foreach ($users_array as $users) {
$aname = $xmlh->getAttribute($users, "agent");
$uname = $xmlh->getAttribute($users, "name");
if ($aname==$_POST["agentname"] || $uname==$_POST["name"]) {
header("Location: error.html");
exit;
}
}
}
// add the user information to the xml file
// get the 'users' element
$users_n = $xmlh->getElement("users");
// create a 'user' element
$user_n = $xmlh->addElement($users_n, "user");
// add the user name and agent name
$xmlh->setAttribute($user_n, "name", $_POST["name"]);
$xmlh->setAttribute($user_n, "agent", $_POST["agentname"]);
// save the XML file
$xmlh->saveFile();
}
else {
header("Location: error.html");
exit;
}
// Cookie done, redirect to client.php (to avoid reloading of page from the client)
header("Location: client.php");
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -