Powerful Chat System – Lesson 2 Today we continue a series of articles on the creation of powerful chat system. Our second lesson will contain next elements: smart chat (ajax, with spam filtering – protection from the frequent messages). I have decided to make registration for next lesson. Hope that it is ok for you.

强大的聊天系统–第2课今天,我们继续撰写有关创建强大的聊天系统的系列文章。 我们的第二课将包含下一个元素:智能聊天(带有垃圾邮件过滤功能的ajax –防止频繁发送的消息)。 我决定报名参加下一堂课。 希望对你没事。

Today I have included next elements: chat processor, plus – slight corrections in our previous sources. All project is well structured: system classes is in ‘classes’ folder, stylesheets in ‘css’ folder, template files in ‘templates’ folder, and – new folder ‘js’ for javascript files.

今天,我包括了下一个元素:聊天处理器,以及-我们以前的资料中有一些小的更正。 所有项目的结构都很好:系统类位于“类”文件夹中,样式表位于“ css”文件夹中,模板文件位于“模板”文件夹中,以及– javascript文件的新文件夹“ js”。

现场演示
打包下载

Now – download the source files and lets start coding !

现在–下载源文件并开始编码!

步骤1. SQL (Step 1. SQL)

This table has got minor changes. I have changed type of field ‘when’.

该表进行了较小的更改。 我已更改字段“何时”的类型。


CREATE TABLE `cs_messages` (`id` int(11) unsigned NOT NULL auto_increment,`sender` int(11) unsigned NOT NULL,`recipient` int(11) unsigned NOT NULL default '0',`message` VARCHAR(255) NOT NULL,`when` int(11) NOT NULL default '0',`room` int(5) unsigned NOT NULL default '0',`type` tinyint(1) unsigned NOT NULL default '0',PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `cs_messages` (`id` int(11) unsigned NOT NULL auto_increment,`sender` int(11) unsigned NOT NULL,`recipient` int(11) unsigned NOT NULL default '0',`message` VARCHAR(255) NOT NULL,`when` int(11) NOT NULL default '0',`room` int(5) unsigned NOT NULL default '0',`type` tinyint(1) unsigned NOT NULL default '0',PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

步骤2. HTML (Step 2. HTML)

This is main (index) page html markup:

这是主页(索引)的html标记:

templates / main_page.html (templates/main_page.html)


<!DOCTYPE html>
<html lang="en" >
<head><title>Powerful Chat System - Lesson 2</title><link href="css/main.css" rel="stylesheet" type="text/css" /><script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body><header><h2>Powerful Chat System - Lesson 2</h2><a href="https://www.script-tutorials.com/powerful-chat-system-lesson-2/" class="stuts">Back to original tutorial on <span>Script Tutorials</span></a></header><div class="container">{form}</div><div class="container"><h2>Main Chat Block</h2><div class="chat_messages">{chat}</div>{input}</div>
</body>
</html>

<!DOCTYPE html>
<html lang="en" >
<head><title>Powerful Chat System - Lesson 2</title><link href="css/main.css" rel="stylesheet" type="text/css" /><script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body><header><h2>Powerful Chat System - Lesson 2</h2><a href="https://www.script-tutorials.com/powerful-chat-system-lesson-2/" class="stuts">Back to original tutorial on <span>Script Tutorials</span></a></header><div class="container">{form}</div><div class="container"><h2>Main Chat Block</h2><div class="chat_messages">{chat}</div>{input}</div>
</body>
</html>

As you can see – I have changed our second container (which contains our ajax chat).

如您所见–我更改了第二个容器(其中包含我们的Ajax聊天)。

templates / login_form.html和templates / logout_form.html (templates/login_form.html and templates/logout_form.html)

These files haven’t changed since last time. Next one new template – chat form:

自上次以来,这些文件未更改。 下一个新模板–聊天表单:

templates / chat.html (templates/chat.html)


<form class="chat_submit_form"><div><input type="text" name="message" /><input type="submit" value="Submit" name="Submit" /></div><div><h3 class="error">Some error occurs during sending message</h3><h3 class="success">Message successfully sent</h3><h3 class="protect">Please wait 5 secs before adding next message</h3></div>
</form>
<script src="js/chat.js"></script>

<form class="chat_submit_form"><div><input type="text" name="message" /><input type="submit" value="Submit" name="Submit" /></div><div><h3 class="error">Some error occurs during sending message</h3><h3 class="success">Message successfully sent</h3><h3 class="protect">Please wait 5 secs before adding next message</h3></div>
</form>
<script src="js/chat.js"></script>

步骤3. CSS (Step 3. CSS)

This file contains updated styles of our chat

此文件包含我们聊天的更新样式

css / main.css (css/main.css)


/* page layout */
*{margin:0;padding:0;
}
body {background-color:#eee;color:#fff;font:14px/1.3 Arial,sans-serif;
}
header {background-color:#212121;box-shadow: 0 -1px 2px #111111;display:block;height:70px;position:relative;width:100%;z-index:100;
}
header h2{font-size:22px;font-weight:normal;left:50%;margin-left:-400px;padding:22px 0;position:absolute;width:540px;
}
header a.stuts,a.stuts:visited{border:none;text-decoration:none;color:#fcfcfc;font-size:14px;left:50%;line-height:31px;margin:23px 0 0 110px;position:absolute;top:0;
}
header .stuts span {font-size:22px;font-weight:bold;margin-left:5px;
}
/* main styles */
.container {background-color: #222;color: #bbb;margin: 20px auto;overflow: hidden;padding: 20px;position: relative;width: 800px;
}
.container h2 {color: #fff;margin-bottom: 10px;
}
.column {float: left;width: 48%;
}
.column:first-child {margin-right: 4%;
}
.column > * {color: #ddd;margin-bottom: 10px;
}
.column h3 {color: #fff;
}
.login_form input,.login_form label {display: block;margin-bottom: 10px;
}
input[type=text], input[type=password], input[type=submit] {-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
input[type=text], input[type=password] {font-size: 16px;height: 30px;margin-right: 10px;width: 200px;
}
input[type=submit]{cursor: pointer;font-size: 16px;font-weight: bold;height: 35px;padding: 5px;
}
/* chat block */
.chat_messages {border: 1px solid #888;box-shadow: 0 0 5px #AAA;color: #000;padding: 10px;
}
.chat_messages h2 {color: #fff;
}
.chat_messages .message {background-color: #fff;margin: 5px;padding: 5px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.chat_messages .message span {color: #444;font-size: 10px;margin-left: 10px;
}
.chat_submit_form {margin: 10px 0px;
}
.chat_submit_form div {float: left;width: 49%;
}
.chat_submit_form .error, .chat_submit_form .success, .chat_submit_form .protect {display: none;
}
.chat_submit_form .error {color: #f55;
}
.chat_submit_form .success {color: #5f5;
}
.chat_submit_form .protect {color: #55f;
}

/* page layout */
*{margin:0;padding:0;
}
body {background-color:#eee;color:#fff;font:14px/1.3 Arial,sans-serif;
}
header {background-color:#212121;box-shadow: 0 -1px 2px #111111;display:block;height:70px;position:relative;width:100%;z-index:100;
}
header h2{font-size:22px;font-weight:normal;left:50%;margin-left:-400px;padding:22px 0;position:absolute;width:540px;
}
header a.stuts,a.stuts:visited{border:none;text-decoration:none;color:#fcfcfc;font-size:14px;left:50%;line-height:31px;margin:23px 0 0 110px;position:absolute;top:0;
}
header .stuts span {font-size:22px;font-weight:bold;margin-left:5px;
}
/* main styles */
.container {background-color: #222;color: #bbb;margin: 20px auto;overflow: hidden;padding: 20px;position: relative;width: 800px;
}
.container h2 {color: #fff;margin-bottom: 10px;
}
.column {float: left;width: 48%;
}
.column:first-child {margin-right: 4%;
}
.column > * {color: #ddd;margin-bottom: 10px;
}
.column h3 {color: #fff;
}
.login_form input,.login_form label {display: block;margin-bottom: 10px;
}
input[type=text], input[type=password], input[type=submit] {-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
input[type=text], input[type=password] {font-size: 16px;height: 30px;margin-right: 10px;width: 200px;
}
input[type=submit]{cursor: pointer;font-size: 16px;font-weight: bold;height: 35px;padding: 5px;
}
/* chat block */
.chat_messages {border: 1px solid #888;box-shadow: 0 0 5px #AAA;color: #000;padding: 10px;
}
.chat_messages h2 {color: #fff;
}
.chat_messages .message {background-color: #fff;margin: 5px;padding: 5px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.chat_messages .message span {color: #444;font-size: 10px;margin-left: 10px;
}
.chat_submit_form {margin: 10px 0px;
}
.chat_submit_form div {float: left;width: 49%;
}
.chat_submit_form .error, .chat_submit_form .success, .chat_submit_form .protect {display: none;
}
.chat_submit_form .error {color: #f55;
}
.chat_submit_form .success {color: #5f5;
}
.chat_submit_form .protect {color: #55f;
}

步骤4. JS (Step 4. JS)

I have created first JS for our chat. At beginning – it contain one function for regular obtaining messages, and handler of form submitting.

我已经为聊天创建了第一个JS。 开始时,它包含一个用于定期获取消息的功能以及表单提交的处理程序。

js / chat.js (js/chat.js)


$(function() {getMessages = function() {$.getJSON('index.php?action=get_last_messages', function(data){if (data.messages) {$('.chat_messages').html(data.messages);}// get recent chat messages in loopsetTimeout(function(){getMessages();}, 5000);});}getMessages();$('.chat_submit_form').submit(function() {$.post('index.php', { message: $('.chat_submit_form input[name=message]').val() },function(data){if (data.result == 1) {$('.chat_submit_form .success').fadeIn('slow', function () {$(this).delay(1000).fadeOut('slow');});} else if (data.result == 2) {$('.chat_submit_form .protect').fadeIn('slow', function () {$(this).delay(1000).fadeOut('slow');});} else {$('.chat_submit_form .error').fadeIn('slow', function () {$(this).delay(1000).fadeOut('slow');});}});return false;});
});

$(function() {getMessages = function() {$.getJSON('index.php?action=get_last_messages', function(data){if (data.messages) {$('.chat_messages').html(data.messages);}// get recent chat messages in loopsetTimeout(function(){getMessages();}, 5000);});}getMessages();$('.chat_submit_form').submit(function() {$.post('index.php', { message: $('.chat_submit_form input[name=message]').val() },function(data){if (data.result == 1) {$('.chat_submit_form .success').fadeIn('slow', function () {$(this).delay(1000).fadeOut('slow');});} else if (data.result == 2) {$('.chat_submit_form .protect').fadeIn('slow', function () {$(this).delay(1000).fadeOut('slow');});} else {$('.chat_submit_form .error').fadeIn('slow', function () {$(this).delay(1000).fadeOut('slow');});}});return false;});
});

步骤5. PHP (Step 5. PHP)

Now, lets review php sources:

现在,让我们回顾一下php来源:

index.php (index.php)


<?php
// set error reporting level
if (version_compare(phpversion(), '5.3.0', '>=') == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
require_once('classes/Services_JSON.php');
require_once('classes/CMySQL.php'); // including service class to work with database
require_once('classes/CLogin.php'); // including service class to work with login processing
// login system init and generation code
$sLoginForm = $GLOBALS['CLogin']->getLoginBox();
$sChat = '<h2>You do not have rights to use chat</h2>';
$sInput = '';
if ($_SESSION['member_id'] && $_SESSION['member_status'] == 'active' && $_SESSION['member_role']) {require_once('classes/CChat.php'); // including service class to work with chat// get last messages$sChat = $GLOBALS['MainChat']->getMessages();if ($_GET['action'] == 'get_last_messages') { // regular updating of messages in chat$oJson = new Services_JSON();header('Content-type: application/json');echo $oJson->encode(array('messages' => $sChat));exit;}// get input form$sInput = $GLOBALS['MainChat']->getInputForm();if ($_POST['message']) { // POST-ing of message$iRes = $GLOBALS['MainChat']->acceptMessage();$oJson = new Services_JSON();header('Content-type: application/json');echo $oJson->encode(array('result' => $iRes));exit;}
}
// draw common page
echo strtr(file_get_contents('templates/main_page.html'), array('{form}' => $sLoginForm, '{chat}' => $sChat, '{input}' => $sInput));

<?php
// set error reporting level
if (version_compare(phpversion(), '5.3.0', '>=') == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
require_once('classes/Services_JSON.php');
require_once('classes/CMySQL.php'); // including service class to work with database
require_once('classes/CLogin.php'); // including service class to work with login processing
// login system init and generation code
$sLoginForm = $GLOBALS['CLogin']->getLoginBox();
$sChat = '<h2>You do not have rights to use chat</h2>';
$sInput = '';
if ($_SESSION['member_id'] && $_SESSION['member_status'] == 'active' && $_SESSION['member_role']) {require_once('classes/CChat.php'); // including service class to work with chat// get last messages$sChat = $GLOBALS['MainChat']->getMessages();if ($_GET['action'] == 'get_last_messages') { // regular updating of messages in chat$oJson = new Services_JSON();header('Content-type: application/json');echo $oJson->encode(array('messages' => $sChat));exit;}// get input form$sInput = $GLOBALS['MainChat']->getInputForm();if ($_POST['message']) { // POST-ing of message$iRes = $GLOBALS['MainChat']->acceptMessage();$oJson = new Services_JSON();header('Content-type: application/json');echo $oJson->encode(array('result' => $iRes));exit;}
}
// draw common page
echo strtr(file_get_contents('templates/main_page.html'), array('{form}' => $sLoginForm, '{chat}' => $sChat, '{input}' => $sInput));

As you can see – I have added chat functionality today.

如您所见–我今天添加了聊天功能。

classes / CLogin.php (classes/CLogin.php)


<?php
class CLogin {// constructorfunction CLogin() {session_start();}// get login box functionfunction getLoginBox() {if (isset($_GET['logout'])) { // logout processingif (isset($_SESSION['member_name']) && isset($_SESSION['member_pass']))$this->performLogout();}if ($_POST && $_POST['username'] && $_POST['password']) { // login processingif ($this->checkLogin($_POST['username'], $_POST['password'], false)) { // successful login$this->performLogin($_POST['username'], $_POST['password']);header( "Location:{$_SERVER['REQUEST_URI']}" );exit;} else { // wrong loginreturn file_get_contents('templates/login_form.html') . '<h2>Username or Password is incorrect</h2>';}} else { // in case if we already logged (on refresh page):if (isset($_SESSION['member_name']) && $_SESSION['member_name'] && $_SESSION['member_pass']) {$aReplaces = array('{name}' => $_SESSION['member_name'],'{status}' => $_SESSION['member_status'],'{role}' => $_SESSION['member_role'],);return strtr(file_get_contents('templates/logout_form.html'), $aReplaces);}// otherwise - draw login formreturn file_get_contents('templates/login_form.html');}}// perform loginfunction performLogin($sName, $sPass) {$this->performLogout();// make variables safe$sName = $GLOBALS['MySQL']->escape($sName);$aProfile = $GLOBALS['MySQL']->getRow("SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'");// $sPassEn = $aProfile['password'];$iPid = $aProfile['id'];$sSalt = $aProfile['salt'];$sStatus = $aProfile['status'];$sRole = $aProfile['role'];$sPass = sha1(md5($sPass) . $sSalt);$_SESSION['member_id'] = $iPid;$_SESSION['member_name'] = $sName;$_SESSION['member_pass'] = $sPass;$_SESSION['member_status'] = $sStatus;$_SESSION['member_role'] = $sRole;}// perform logoutfunction performLogout() {unset($_SESSION['member_id']);unset($_SESSION['member_name']);unset($_SESSION['member_pass']);unset($_SESSION['member_status']);unset($_SESSION['member_role']);}// check loginfunction checkLogin($sName, $sPass, $isHash = true) {// make variables safe$sName = $GLOBALS['MySQL']->escape($sName);$sPass = $GLOBALS['MySQL']->escape($sPass);$aProfile = $GLOBALS['MySQL']->getRow("SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'");$sPassEn = $aProfile['password'];if ($sName && $sPass && $sPassEn) {if (! $isHash) {$sSalt = $aProfile['salt'];$sPass = sha1(md5($sPass) . $sSalt);}return ($sPass == $sPassEn);}return false;}
}
$GLOBALS['CLogin'] = new CLogin();

<?php
class CLogin {// constructorfunction CLogin() {session_start();}// get login box functionfunction getLoginBox() {if (isset($_GET['logout'])) { // logout processingif (isset($_SESSION['member_name']) && isset($_SESSION['member_pass']))$this->performLogout();}if ($_POST && $_POST['username'] && $_POST['password']) { // login processingif ($this->checkLogin($_POST['username'], $_POST['password'], false)) { // successful login$this->performLogin($_POST['username'], $_POST['password']);header( "Location:{$_SERVER['REQUEST_URI']}" );exit;} else { // wrong loginreturn file_get_contents('templates/login_form.html') . '<h2>Username or Password is incorrect</h2>';}} else { // in case if we already logged (on refresh page):if (isset($_SESSION['member_name']) && $_SESSION['member_name'] && $_SESSION['member_pass']) {$aReplaces = array('{name}' => $_SESSION['member_name'],'{status}' => $_SESSION['member_status'],'{role}' => $_SESSION['member_role'],);return strtr(file_get_contents('templates/logout_form.html'), $aReplaces);}// otherwise - draw login formreturn file_get_contents('templates/login_form.html');}}// perform loginfunction performLogin($sName, $sPass) {$this->performLogout();// make variables safe$sName = $GLOBALS['MySQL']->escape($sName);$aProfile = $GLOBALS['MySQL']->getRow("SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'");// $sPassEn = $aProfile['password'];$iPid = $aProfile['id'];$sSalt = $aProfile['salt'];$sStatus = $aProfile['status'];$sRole = $aProfile['role'];$sPass = sha1(md5($sPass) . $sSalt);$_SESSION['member_id'] = $iPid;$_SESSION['member_name'] = $sName;$_SESSION['member_pass'] = $sPass;$_SESSION['member_status'] = $sStatus;$_SESSION['member_role'] = $sRole;}// perform logoutfunction performLogout() {unset($_SESSION['member_id']);unset($_SESSION['member_name']);unset($_SESSION['member_pass']);unset($_SESSION['member_status']);unset($_SESSION['member_role']);}// check loginfunction checkLogin($sName, $sPass, $isHash = true) {// make variables safe$sName = $GLOBALS['MySQL']->escape($sName);$sPass = $GLOBALS['MySQL']->escape($sPass);$aProfile = $GLOBALS['MySQL']->getRow("SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'");$sPassEn = $aProfile['password'];if ($sName && $sPass && $sPassEn) {if (! $isHash) {$sSalt = $aProfile['salt'];$sPass = sha1(md5($sPass) . $sSalt);}return ($sPass == $sPassEn);}return false;}
}
$GLOBALS['CLogin'] = new CLogin();

This class is updated too. I have decided to add ‘member_id’ in sessions too. It will useful afterward.

此类也将更新。 我也决定在会话中添加“ member_id”。 以后会有用。

类/CMySQL.php (classes/CMySQL.php)

This is database service class. Available in package. Pay attention – database settings of our project is in this file.

这是数据库服务类。 封装形式。 注意–该项目的数据库设置位于此文件中。

classes / Services_JSON.php (classes/Services_JSON.php)

This is JSON service class. Available in package.

这是JSON服务类。 封装形式。

classes / CChat.php (classes/CChat.php)


<?php
class CChat {// constructorfunction CChat() {}// add to DB messagefunction acceptMessage() {$sName = $GLOBALS['MySQL']->escape($_SESSION['member_name']);$iPid = (int)$_SESSION['member_id'];$sMessage = $GLOBALS['MySQL']->escape($_POST['message']);if ($iPid && $sName != '' && $sMessage != '') {$sSQL = "SELECT `id`FROM `cs_messages`WHERE `sender` = '{$iPid}' AND UNIX_TIMESTAMP( ) - `when` < 5LIMIT 1";$iLastId = $GLOBALS['MySQL']->getOne($sSQL);if ($iLastId) return 2; // as protection from very often messages$bRes = $GLOBALS['MySQL']->res("INSERT INTO `cs_messages` SET `sender` = '{$iPid}', `message` = '{$sMessage}', `when` = UNIX_TIMESTAMP()");return ($bRes) ? 1 : 3;}}// return input text formfunction getInputForm() {return file_get_contents('templates/chat.html');}// get last 10 messagesfunction getMessages() {$sSQL = "SELECT `a` . * , `cs_profiles`.`name` , UNIX_TIMESTAMP( ) - `a`.`when` AS 'diff'FROM `cs_messages` AS `a`INNER JOIN `cs_profiles` ON `cs_profiles`.`id` = `a`.`sender`ORDER BY `a`.`id` DESCLIMIT 10";$aMessages = $GLOBALS['MySQL']->getAll($sSQL);asort($aMessages);// create list of messages$sMessages = '';foreach ($aMessages as $i => $aMessage) {$sExStyles = $sExJS = '';$iDiff = (int)$aMessage['diff'];if ($iDiff < 7) { // less than 7 seconds$sExStyles = 'style="display:none;"';$sExJS = "<script> $('#message_{$aMessage['id']}').fadeIn('slow'); </script>";}$sWhen = date("H:i:s", $aMessage['when']);$sMessages .= '<div class="message" id="message_'.$aMessage['id'].'" '.$sExStyles.'><b>' . $aMessage['name'] . ':</b> ' . $aMessage['message'] . '<span>(' . $sWhen . ')</span></div>' . $sExJS;}return $sMessages;}
}
$GLOBALS['MainChat'] = new CChat();

<?php
class CChat {// constructorfunction CChat() {}// add to DB messagefunction acceptMessage() {$sName = $GLOBALS['MySQL']->escape($_SESSION['member_name']);$iPid = (int)$_SESSION['member_id'];$sMessage = $GLOBALS['MySQL']->escape($_POST['message']);if ($iPid && $sName != '' && $sMessage != '') {$sSQL = "SELECT `id`FROM `cs_messages`WHERE `sender` = '{$iPid}' AND UNIX_TIMESTAMP( ) - `when` < 5LIMIT 1";$iLastId = $GLOBALS['MySQL']->getOne($sSQL);if ($iLastId) return 2; // as protection from very often messages$bRes = $GLOBALS['MySQL']->res("INSERT INTO `cs_messages` SET `sender` = '{$iPid}', `message` = '{$sMessage}', `when` = UNIX_TIMESTAMP()");return ($bRes) ? 1 : 3;}}// return input text formfunction getInputForm() {return file_get_contents('templates/chat.html');}// get last 10 messagesfunction getMessages() {$sSQL = "SELECT `a` . * , `cs_profiles`.`name` , UNIX_TIMESTAMP( ) - `a`.`when` AS 'diff'FROM `cs_messages` AS `a`INNER JOIN `cs_profiles` ON `cs_profiles`.`id` = `a`.`sender`ORDER BY `a`.`id` DESCLIMIT 10";$aMessages = $GLOBALS['MySQL']->getAll($sSQL);asort($aMessages);// create list of messages$sMessages = '';foreach ($aMessages as $i => $aMessage) {$sExStyles = $sExJS = '';$iDiff = (int)$aMessage['diff'];if ($iDiff < 7) { // less than 7 seconds$sExStyles = 'style="display:none;"';$sExJS = "<script> $('#message_{$aMessage['id']}').fadeIn('slow'); </script>";}$sWhen = date("H:i:s", $aMessage['when']);$sMessages .= '<div class="message" id="message_'.$aMessage['id'].'" '.$sExStyles.'><b>' . $aMessage['name'] . ':</b> ' . $aMessage['message'] . '<span>(' . $sWhen . ')</span></div>' . $sExJS;}return $sMessages;}
}
$GLOBALS['MainChat'] = new CChat();

This is our new class for chat processor. For now – it contain only 3 functions: acceptMessage, getInputForm and getMessages.

这是我们的聊天处理器新类。 目前,它仅包含3个函数:acceptMessage,getInputForm和getMessages。

现场演示
存档下载

结论 (Conclusion)

I will hope that our new series of articles of chat system creation will be useful and interesting for you. If you want to share your ideas, or you noticed any weakness – don’t hesitate to contact us. Good luck and welcome back!

我希望我们有关聊天系统创建的新系列文章对您有用和有趣。 如果您想分享自己的想法,或者发现任何弱点,请随时与我们联系。 祝你好运,欢迎回来!

翻译自: https://www.script-tutorials.com/powerful-chat-system-lesson-2/

强大的聊天系统–第2课相关推荐

  1. 中职计算机应用基础微课获奖视频,浅谈微课在中职计算机应用基础教学中的应用...

    作者:陶俊 本文字数:2407 [摘 要] 伴随数字化.信息化和移动互联等为特征的智慧时代已经到来,我国教育也随之进入信息化时代的重要时期.微课作为一种新兴的教学手段快速发展,为教育事业注入新的血液. ...

  2. 《Adobe Illustrator CS6中文版经典教程(彩色版)》—第0课0.1简介

    本节书摘来自异步社区<Adobe Illustrator CS6中文版经典教程(彩色版)>一书中的第0课0.1节简介,作者[美]Adobe公司,更多章节内容可以访问云栖社区"异步 ...

  3. 送上“曾国藩日课十三条”

    随着年龄的增长,深深的感觉到自己大大不如从前,不管是从生理上还是从心理上. 小时候,每个人都有个梦想,我也是,我的梦想是当一名科学家,走出校园,步入社会后,渐渐离现实近了,所见,所闻,所想,都是残酷的 ...

  4. 谈谈神秘的ES6——(一)初识ECMAScript

    2019独角兽企业重金招聘Python工程师标准>>> 谈谈神秘的ES6--(一)初识ECMAScript 在<零基础入门JavaScript>我们就说过,ECMAScr ...

  5. python课程将主要介绍哪些内容-Python课程详细介绍

    渡课 Python 课程开课啦,学Python就来渡课IT 模块一:Python语言部分 课程介绍 介绍Python的诞生,Python有什么独特的特点,它适合用在哪些地方,不适合用在哪些地方,以及P ...

  6. python课程主要介绍哪些内容_Python课程详细介绍

    渡课 Python 课程开课啦,学Python就来渡课IT 模块一:Python语言部分 课程介绍 介绍Python的诞生,Python有什么独特的特点,它适合用在哪些地方,不适合用在哪些地方,以及P ...

  7. 地府后台管理系统30.已经在开发中,介绍下目前的工作进度和未来展望

    一.概况 博文<程序员把地府后台管理系统做出来了,还有3.0版本!>出来后,得到了大家的一致认可,也有好多朋友希望能真的在这个原型图的基础上把这个系统开发出来,热心网友"走上删库 ...

  8. 金融直播APP方案开发

    分享一下英唐众创开发的金融直播APP解决方案.随着视频直播风靡全球,视频直播已成为众多传统行业和互联网行业争夺的"香饽饽".金融行业当然也不例外,在当今"互联网+&quo ...

  9. 薪火培训电控第一讲——单片机与GPIO

    薪火培训电控第一讲--单片机与GPIO 关于单片机 初识单片机 时钟 GPIO简介 GPIO函数 八种输入输出模式 Cube和keil使用简介 使用cube建立项目 keil使用 作业讲解与点评 讲解 ...

最新文章

  1. iphone开蓝牙wifi上网慢_桌面运维:WiFi信号强,网速却很慢?这样操作就能搞定!...
  2. 使用xib封装一个view的步骤
  3. vuecli4 启动_vue 常见命令 (启动 部署)
  4. Swift 设置字体
  5. mysql数据剪切到新表_6、MySQL核心DDL语句
  6. 分布式系统开发工具包 —— 基于Kryo的Java对象序列化
  7. 国防现代化的数据_Linux容器如何解决国防虚拟化问题
  8. linux无密码scp,linux通过ssh-keygen实现无密码scp文件和目录
  9. Docker实践(七)部署SpringBoot微服务
  10. 学习笔记 十八: kickstart
  11. MyBatsi-Mapper映射文件
  12. OUTLOOK EXPRESS的数据备份
  13. 介绍一个工具给大家,做网站时,经常要上传文件到外网服务器,但是上传时往往需要很长时间,如果有一个文件对比工具……...
  14. windows系统bat批处理 开机一键多个程序
  15. 安装DL380gen10
  16. 计算机2.0培训心得,教育信息化20培训心得体会
  17. cortex M7 MPU 总结
  18. 【scala】练习题
  19. 互联网招聘的阴阳两极
  20. 阿里云服务器搭建WORDPRESS案例

热门文章

  1. 读取MNIST数据集并显示数据集图片 完全解析
  2. 基于C++结构体的通讯录系统
  3. python语句结尾分号吗_Python 为什么不用分号作终止符?
  4. matlab怎么画威布尔分布,matlab绘制威布尔分布曲线.docx
  5. python怎么写中文至excel_Python操作Excel_输出所有内容(包含中文)
  6. 赣州市光华职业学校计算机部,2019年赣州市中职学校技能竞赛正式开赛
  7. java毕业设计汽配管理系统(附源码、数据库)
  8. 我们的wifi,真的安全吗
  9. Unity+ Photon服务器实时对战游戏——Photon服务器介绍(一)
  10. 焦炭市场相对强势格局未结束