#PHP #MySQL數據操作 #線上聊天 PHP實現線上聊天與MySQL的“增查刪改”

来源:https://www.cnblogs.com/pyublog/archive/2022/12/23/17000094.html
-Advertisement-
Play Games

目錄 1.目標圖 2.項目簡介 3.目錄結構 4.建立MySQL表 5.實現過程 5.1 index.php 5.2 data.php 5.2 method.php 5.3 case.php 5.4 main.js 5.5 css/style.css 5.6 img\icon01.png 5.7 j ...


 

目錄

1.目標圖

2.項目簡介 

3.目錄結構 

4.建立MySQL表 

5.實現過程 

5.1 index.php

5.2 data.php

 5.2 method.php

5.3  case.php

5.4 main.js

5.5 css/style.css

5.6 img\icon01.png 

 5.7 js\jquery.min.js

6.總結


 

1.目標圖

編輯

2.項目簡介 

       這個聊天室本來是本人網站下的一個小功能,但是由於伺服器到期,於是把它分享出來供大家參考。

       如果要完成這個項目您需要已配置好的PHP+MySQL環境,我使用的是本地搭建的內網伺服器,但建議使用已配置好的專業伺服器,這樣可能會更簡單。

       要在本地配置伺服器可以參看下麵這篇文章:

Windows使用寶塔面板一鍵快速搭建本地伺服器環境

3.目錄結構 

        請在您的伺服器根目錄下創建如下目錄結構:

/根目錄
/css
-style.css
/img
-icon01.png
/js
-jquery.min.js
/根目錄
-case.php
-data.php
-index.php
-main.js
-method.php

 

創建目錄結構
編輯

 

4.建立MySQL表 

create table `chatnote` (
	`cn_id` int (10),
	`cn_name` varchar (150),
	`cn_icon` varchar (765),
	`cn_text` varchar (765),
	`cn_time` varchar (72)
); 
建立MySQL表
編輯
建表完成
編輯

 

5.實現過程 

5.1 index.php

      這是聊天室的主頁面:

<?php 
ini_set('session.cookie_httponly', 1);
session_start();
if (isset($_SESSION['cn_name'])) {
  $size="none";
  $_val=$_SESSION['cn_name'];
}else{
  $size="block";
  $_val="請設定昵稱";
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>彭_Yu-線上聊天室</title>
<link type="text/css" href="./css/style.css" rel="stylesheet" />
<script src="./js/jquery.min.js"></script>
  <style>
    body{
      margin: 0px;
      height: 100%;
      background: #ccc;
	  background-attachment: fixed;
      background-size:cover;
      cursor: url(js/p1.ico),auto;

    }
  body,td,th {
	font-family: "Helvetica Neue";
}
  </style>
</head>

<body>
  
  <div class="box">
    <div class="box-title">
      <h3>彭_Yu-線上聊天室</h3>
    </div>
    
    <div class="box-case">
      
      <div class="case-box">
        <div class="case-left">
          <div class="case-msg">
          <i class="horn"></i></div>
        </div>
      </div>
      <div class="case-box">
        <div class="case-right"> </div>
      </div>
      
      <div class="case-box">
        <div class="case-right">
          <div class="case-msg2">
            <i class="horn2"></i></div>
        </div>
      </div>
    
    </div>
    
    <div class="box-inpu">
    
      <textarea class="box-text" style= "resize:none" name="text"></textarea>
      <div class="butt">
        <button id="send">發送</button>
        <button id="Nickname">設定昵稱</button>
      </div>
    </div>

    <div class="box-tips" style="display:<?php echo $size;?>;">
      <div class="tips-tit">
        設置昵稱
      </div>
      <input class="ni" type="text" name="" value="<?php echo $_val;?>">
      <button class="nide">保存昵稱</button>
    </div>
    
  </div>

<script type="text/javascript">
var upok = '設置成功';
var upps = '昵稱不能為空!';
</script>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Copyright©2021-2022 版權所有:彭_Yu
</script>
</canvas>
</body>
</html>

5.2 data.php

 這是資料庫連接文件,資料庫信息需要改成你的資料庫信息:

<?php
$host= "localhost";//資料庫連接地址
$username = "root";//資料庫賬號
$password = "root123456";//資料庫密碼
$dbname = "pengxiazai";//資料庫名

try{
    $conn = new PDO("mysql:host=$host;dbname=$dbname","$username","$password");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $conn->exec('set names utf8');
}
catch(PDOException $e){
    die("資料庫連接失敗".$e->getMessage());
}

 5.2 method.php

        這個文件用於向伺服器發送表單:

<?php
ini_set('session.cookie_httponly', 1);
session_start();
$Get_time = time();
if (isset($_POST['name'])&&isset($_POST['text'])&&isset($_POST['state'])) {
	$_name = $_POST['name'];
	$_text = $_POST['text'];
	$_icon = 'img/icon01.png';
	if ($_text!='') {
		include "data.php";
		$sql = "INSERT INTO chatnote (cn_name,cn_icon,cn_text,cn_time) VALUES ('".$_name."', '".$_icon."','".$_text."','".$Get_time."')";
		$conn->exec($sql);
		$conn = null;
		echo 'ok';
	}
}
if (isset($_POST['name'])&&isset($_POST['state'])) {
	$_SESSION['cn_name'] = $_POST['name'];
	echo 'ok';
}

5.3  case.php

     這個文件用於操作資料庫:

<?php
ini_set('session.cookie_httponly', 1);
session_start();
include "data.php";
date_default_timezone_set('PRC');
$sql = "SELECT * FROM chatnote";
$stmt = $conn->prepare($sql);
$stmt->execute(array());
$_data = "";
$me = $_SESSION['cn_name'];
$i=0;
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
	if ($row['cn_name']==$me) {
    $_data .= '
    <div class="case-box">
        <span class="case-time">'.date("Y-m-d H:i:s",$row['cn_time']).'</span>
        <div class="case-right">
          <img src="'.htmlentities($row['cn_icon']).'" />
          <span class="case-name2">'.htmlentities($row['cn_name']).'</span>
          <div class="case-msg2">
            <i class="horn2"></i>
            '.htmlentities($row['cn_text']).'
          </div>
        </div>
      </div>';
  }else{
    $_data .= '
    <div class="case-box">
        <span class="case-time">'.date("Y-m-d H:i:s",$row['cn_time']).'</span>
        <div class="case-left">
          <img src="'.htmlentities($row['cn_icon']).'" />
          <span class="case-name">'.htmlentities($row['cn_name']).'</span>
          <div class="case-msg">
            <i class="horn"></i>
            '.htmlentities($row['cn_text']).'
          </div>
        </div>
      </div>';
  }
}
$_data .= '<div class="case-top"></div>';
echo $_data;
$conn = null;

5.4 main.js

      頁面通用js文件:

查看代碼-由於代碼過長已摺疊
(function(){
var KasperskyLab = {SIGNATURE:"7D8B79A2-8974-4D7B-A76A-F4F29624C06BrybkdR7SHpQjkrd7RdE_eafXe2RFDchmt48e_sgv66w2sicuToIKurG7iojSolvzNHjHt5mSZXdL7gAobQnafg",PREFIX:"http://me.kis.v2.scr.kaspersky-labs.com/",INJECT_ID:"FD126C42-EBFA-4E12-B309-BB3FDD723AC1",RESOURCE_ID:"E3E8934C-235A-4B0E-825A-35A08381A191",IsWebExtension: function(){return false;}}; var KasperskyLab = (function (context) {
    function GetClass(obj) {
        if (typeof obj === "undefined")
            return "undefined";
        if (obj === null)
            return "null";
        return Object.prototype.toString.call(obj)
            .match(/^\[object\s(.*)\]$/)[1];
    }
    var exports = {}, undef;
    function ObjectToJson(object) {
        if (object === null || object == Infinity || object == -Infinity || object === undef)
            return "null";
        var className = GetClass(object);
        if (className == "Boolean") {
            return "" + object;
        } else if (className == "Number") {
            return window.isNaN(object) ? "null" : "" + object;
        } else if (className == "String") {
            var escapedStr = "" + object;
            return "\"" + escapedStr.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"") + "\"";
        }
        if (typeof object == "object") {
            if (!ObjectToJson.check) ObjectToJson.check = [];
            for (var i=0, chkLen=ObjectToJson.check.length ; i<chkLen ; ++i) {
                if (ObjectToJson.check[i] === object) {
                    throw new TypeError();
                }
            }
            ObjectToJson.check.push(object);
            var str = '';
            if (className == "Array" || className == "Array Iterator") {
                for (var index = 0, length = object.length; index < length; ++index) {
                    str += ObjectToJson(object[index]) + ',';
                }
                ObjectToJson.check.pop();
                return "["+str.slice(0,-1)+"]";
            } else {
                for (var property in object) {
                    if (object.hasOwnProperty(property)) {
                        str += '"' + property + '":' + ObjectToJson(object[property]) + ',';
                    }
                }
                ObjectToJson.check.pop();
                return "{"+str.slice(0,-1)+"}";
            }
        }
        return undef;
    }
    exports.stringify = function (source) {
        return ObjectToJson(source);
    };
    var parser = {
        source : null,
        grammar : /^[\x20\t\n\r]*(?:([,:\[\]{}]|true|false|null)|(-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)|"((?:[^\r\n\t\\\"]|\\(?:["\\\/trnfb]|u[0-9a-fA-F]{4}))*)")/,
        ThrowError : function() {
            throw new SyntaxError('JSON syntax error');
        },
        NextToken : function(token) {
            this.source = token.input.slice(token[0].length);
            return this.grammar.exec(this.source);
        },
        ParseArray : function(){
            var token = this.grammar.exec(this.source),
                parseItem = token && token[1] != ']',
                result = [];
            for(;;token = this.NextToken(token)) {
                if (!token)
                    this.ThrowError();
                if (parseItem) {
                    result.push(this.ParseValue(token));
                    token = this.grammar.exec(this.source);
                } else {
                    if (token[1]) {
                        if (token[1] == ']') {
                            break;
                        } else if (token[1] != ',') {
                            this.ThrowError();
                        }
                    } else {
                        this.ThrowError();
                    }
                }
                parseItem = !parseItem;
            }
            return result;
        },
        ParseObject : function(){
            var propertyName, parseProperty = true, result = {};
            for(var token = this.grammar.exec(this.source);;token = this.NextToken(token)) {
                if (!token)
                    this.ThrowError();
                if (parseProperty) {
                    if (token[1] && token[1] == '}') {
                        break;
                    } else if (token[1] || token[2] || !token[3]) {
                        this.ThrowError();
                    }
                    propertyName = token[3];
                    token = this.NextToken(token);
                    if (!token || !token[1] || token[1] != ':')
                        this.ThrowError();
                    parseProperty = false;
                } else {
                    if (!propertyName)
                        this.ThrowError();
                    result[ propertyName ] = this.ParseValue(token);
                    token = this.NextToken(this.grammar.exec(this.source));
                    if (token[1]) {
                        if (token[1] == '}') {
                            break;
                        } else if (token[1] != ',') {
                            this.ThrowError();
                        }
                    } else {
                        this.ThrowError();
                    }
                    propertyName = undef;
                    parseProperty = true;
                }
            }
            return result;
        },
        ParseValue : function(token){
            if (token[1]) {
                switch (token[1]){
                    case '[' :
                        this.source = this.source.slice(token[0].length);
                        return this.ParseArray();
                    case '{' :
                        this.source = this.source.slice(token[0].length);
                        return this.ParseObject();
                    case 'true' :
                        return true;
                    case 'false' :
                        return false;
                    case 'null' :
                        return null;
                    default:
                        this.ThrowError();
                }
            } else if (token[2]) {
                return  +token[2];
            }
            return token[3].replace(/\\(?:u(.{4})|(["\\\/'bfnrt]))/g, function(substr, utfCode, esc){
                if(utfCode)
                {
                    return String.fromCharCode(parseInt(utfCode, 16));
                }
                else
                {
                    switch(esc) {
                        case 'b': return '\b';
                        case 'f': return '\f';
                        case 'n': return '\n';
                        case 'r': return '\r';
                        case 't': return '\t';
                        default:
                            return esc;
                    }
                }
            });
        },
        Parse : function(str) {
            if ('String' != GetClass(str))
                throw new TypeError();
            this.source = str;
            var token = this.grammar.exec(this.source);
            if (!token)
                this.ThrowError();
            return this.ParseValue(token);
        }
    };
    exports.parse = function (source) {
        return parser.Parse(source);
    };
    context['JSONStringify'] = exports.stringify;
    context['JSONParse'] = exports.parse;
    return context;
}).call(this, KasperskyLab || {});
 var KasperskyLab = (function ( ns) {
    ns.FunctionBind = Function.prototype.bind;
    ns.MaxRequestDelay = 2000;
    ns.Log = function(message)
    {
        try
        {
            if (!message)
                return;
            if (window.plugin && window.plugin.log)
                window.plugin.log(message);
        }
        catch(e)
        {}
    };
    ns.SessionLog = function()
    {};
    ns.SessionError = function()
    {};
    ns.GetDomainName = function() 
    {
        return document.location.hostname;
    }
    function GetHostAndPort(url)
    {
        var hostBeginPos = url.indexOf('//');
        if (hostBeginPos == -1)
        {
            url = document.baseURI || '';
            hostBeginPos = url.indexOf('//');
            if (hostBeginPos == -1)
                return '';
        }
        hostBeginPos += 2;
        var hostEndPos = url.indexOf('/', hostBeginPos);
        if (hostEndPos == -1)
            hostEndPos = url.length;
        var originParts = url.substring(0, hostEndPos).split('@');
        var origin = originParts.length > 1 ? originParts[1] : originParts[0];
        return origin[0] === "/" ? document.location.protocol + origin : origin;
    }
    ns.IsCorsRequest = function(url, initiator)
    {
        url = typeof(url) != 'string' ? url.toString() : url;
        var urlOrigin = GetHostAndPort(url);
        var initiatorOrigin = GetHostAndPort(initiator);
        return !!urlOrigin && !!initiatorOrigin && urlOrigin != initiatorOrigin;
    }
    var originalWindowOpen = window.open;
    ns.WindowOpen = function(url)
    {
        if (typeof(originalWindowOpen) === "function")
            originalWindowOpen.call(window, url);
        else
            originalWindowOpen(url);    
    }
    ns.EncodeURI = encodeURI;
    ns.GetResourceSrc = function(resourceName)
    {
        return ns.GetBaseUrl() + ns.RESOURCE_ID + resourceName;
    };
    ns.IsRelativeTransport = function()
    {
        return ns.PREFIX == "/";
    }
    ns.GetBaseUrl = function()
    {
        if (!ns.IsRelativeTransport())
            return ns.PREFIX;
        return document.location.protocol + "//" + document.location.host + "/";
    };
    ns.AddEventListener = function(element, name, func)
    {
        if ("addEventListener" in element)
            element.addEventListener(name, 
                function(e) 
                {
                    try
                    {
                        func(e || window.event);
                    }
                    catch (e)
                    {
                        ns.SessionError(e);
                    }
                }, true);
        else
            element.attachEvent("on" + name, 
                function(e)
                {
                    try
                    {
                        func.call(element, e || window.event);
                    }
                    catch (e)
                    {
                        ns.SessionError(e);
                    }
                });
    };
    ns.AddRemovableEventListener = function ( element,  name,  func) {
        if (element.addEventListener)
            element.addEventListener(name, func, true);
        else
            element.attachEvent('on' + name, func);
    };
    ns.RunModule = function(func, timeout)
    {
        if (document.readyState === "loading")
        {
            if (timeout)
                ns.SetTimeout(func, timeout);
            if (document.addEventListener)
                ns.AddEventListener(document, "DOMContentLoaded", func);
            ns.AddEventListener(document, "load", func);
        }
        else
        {
            try
            {
                func();
            }
            catch (e)
            {
                ns.SessionError(e);
            }
        }
    };
    ns.RemoveEventListener = function ( element,  name, func) {
        if (element.removeEventListener)
            element.removeEventListener(name, func, true);
        else
            element.detachEvent('on' + name, func);
    };
    ns.SetTimeout = function(func, timeout)
    {
        return setTimeout(
            function()
            {
                try
                {
                    func();
                }
                catch (e)
                {
                    ns.SessionError(e);
                }
            }, timeout);
    }
    ns.SetInterval = function(func, interval)
    {
        return setInterval(
            function()
            {
                try
                {
                    func();
                }
                catch (e)
                {
                    ns.SessionError(e);
                }
            }, interval);
    }
    function InsertStyleRule( style,  rule) {
        if (style.styleSheet)
        {
            style.styleSheet.cssText += rule + '\n';
        }
        else
        {
            style.appendChild(document.createTextNode(rule));
            ns.SetTimeout(
                function()
                {
                    if (!style.sheet)
                        return;
                    var rules = style.sheet.cssRules || style.sheet.rules;
                    if (rules && rules.length === 0)
                        style.sheet.insertRule(rule);
                }, 500);
        }
    }
    ns.AddStyles = function (rules)
    {
        return ns.AddDocumentStyles(document, rules);
    }
    ns.AddDocumentStyles = function(document, rules)
    {
        if (typeof rules !== 'object' || rules.constructor !== Array) {
            return;
        }
        var styles = [];
        for (var i = 0, len = rules.length; i < len; )
        {
            var style = document.createElement('style');
            style.type = 'text/css';
            style.setAttribute('nonce', ns.ContentSecurityPolicyNonceAttribute);
            for (var n = 0; n < 4 && i < len; ++n, ++i)
            {
                var rule = rules[i];
                if (document.querySelectorAll)
                {
                    InsertStyleRule(style, rule);
                }
                else
                {
                    var styleBegin = rule.lastIndexOf('{');
                    if (styleBegin == -1)
                        continue;
                    var styleText = rule.substr(styleBegin);
                    var selectors = rule.substr(0, styleBegin).split(',');
                    if (style.styleSheet)
                    {
                        var cssText = '';
                        for (var j = 0; j != selectors.length; ++j)
                            cssText += selectors[j] + styleText + '\n';
                        style.styleSheet.cssText += cssText;
                    }
                    else
                    {
                        for (var j = 0; j != selectors.length; ++j)
                            style.appendChild(document.createTextNode(selectors[j] + styleText));
                    }
                }
            }
            if (document.head)
                document.head.appendChild(style);
            else
                document.getElementsByTagName('head')[0].appendChild(style);
            styles.push(style);
        }
        return styles;
    };
    ns.AddCssLink = function(document, href, loadCallback, errorCallback)
    {
        var link = document.createElement("link");
        link.type = "text/css";
        link.rel = "stylesheet";
        link.href = href;
        if (loadCallback)
        {
            ns.AddEventListener(link, "load", function()
                {
                    try
                    {
                        link && link.sheet && link.sheet.cssText;   
                        loadCallback();
                    }
                    catch(e)
                    {
                        if (errorCallback)
                            errorCallback();
                    }
                });
        }
        if (errorCallback)
        {
            ns.AddEventListener(link, "error",
                function()
                {
                    errorCallback();
                    ns.SessionError("failed load resource: " + href);
                });
        }
        if (document.head)
            document.head.appendChild(link);
        else
            document.getElementsByTagName("head")[0].appendChild(link);
    }
    ns.GetCurrentTime = function () {
        return new Date().getTime();
    };
    ns.GetPageScroll = function()
    {
        return {
                left: (document.documentElement && document.documentElement.scrollLeft) || document.body.scrollLeft,
                top: (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop
            };
    };
    ns.GetPageHeight = function()
    {
        return document.documentElement.clientHeight || document.body.clientHeight;
    };
    ns.GetPageWidth = function()
    {
        return document.documentElement.clientWidth || document.body.clientWidth;
    };
    ns.IsDefined = function (variable)
    {
        return "undefined" !== typeof(variable);
    };
    ns.StopProcessingEvent = function(evt)
    {
        if (evt.preventDefault)
            evt.preventDefault();
        else
            evt.returnValue = false;
        if (evt.stopPropagation)
            evt.stopPropagation();
        if (ns.IsDefined(evt.cancelBubble))
            evt.cancelBubble = true;
    }
    ns.AddIframeDoctype = function(element)
    {
        var frameDocument = element.contentDocument || element.contentWindow.document;
        if (document.implementation && document.implementation.createDocumentType)
        {
            var newDoctype = document.implementation.createDocumentType('html', '', '');
            if (frameDocument.childNodes.length)
                frameDocument.insertBefore(newDoctype, frameDocument.childNodes[0]);
            else
                frameDocument.appendChild(newDoctype);
        }
        else
        {
            frameDocument.write("<!DOCTYPE html>");
            frameDocument.close();
        }
    }
    function IsElementNode(node)
    {
        return node.nodeType === 1; 
    }
    function IsNodeContainsElementWithTag(node, observeTag)
    {
        return observeTag == "*" || (IsElementNode(node) && (node.tagName.toLowerCase() === observeTag || node.getElementsByTagName(observeTag).length > 0));
    }
    function MutationChangeObserver(observeTag)
    {
        var m_observer;
        var m_callback;
        var m_functionCheckInteresting = observeTag ? function(node){return IsNodeContainsElementWithTag(node, observeTag);} : IsElementNode;
        function ProcessNodeList(nodeList)
        {
            for (var i = 0; i < nodeList.length; ++i)
            {
                if (m_functionCheckInteresting(nodeList[i]))
                    return true;
            }
            return false;
        }
        function ProcessDomChange(records)
        {
            if (!m_callback)
                return;
            for (var i = 0; i < records.length; ++i)
            {
                var record = records[i];
                if ((record.addedNodes.length && ProcessNodeList(record.addedNodes)) ||
                    (record.removedNodes.length && ProcessNodeList(record.removedNodes)))
                {
                    m_callback();
                    return;
                }
            }
        }
        this.Start = function(callback)
        {
            m_callback = callback;
            m_observer = new MutationObserver(ProcessDomChange);
            m_observer.observe(document, { childList: true, subtree: true });
        };
        this.Stop = function()
        {
            m_observer.disconnect();
            m_callback = null;
        };
    }
    function DomEventsChangeObserver(observeTag)
    {
        var m_callback;
        var m_functionCheckInteresting = observeTag ? function(node){return IsNodeContainsElementWithTag(node, observeTag);} : IsElementNode;
        function ProcessEvent(event)
        {
            if (!m_callback)
                return;
            if (m_functionCheckInteresting(event.target))
                m_callback();
        }
        this.Start = function(callback)
        {
            ns.AddRemovableEventListener(window, "DOMNodeInserted", ProcessEvent);
            ns.AddRemovableEventListener(window, "DOMNodeRemoved", ProcessEvent);
            m_callback = callback;
        }
        this.Stop = function()
        {
            ns.RemoveEventListener(window, "DOMNodeInserted", ProcessEvent);
            ns.RemoveEventListener(window, "DOMNodeRemoved", ProcessEvent);
            m_callback = null;
        }
    }
    function TimeoutChangeObserver(observeTag)
    {
        var m_interval;
        var m_callback;
        var m_tagCount;
        var m_attribute = 'klot_' + ns.GetCurrentTime();
        function IsChangesOccure(nodeList)
        {
            for (var i = 0; i < nodeList.length; ++i)
                if (!nodeList[i][m_attribute])
                    return true;
            return false;
        }
        function FillTagInfo(nodeList)
        {
            m_tagCount = nodeList.length;
            for (var i = 0; i < m_tagCount; ++i)
                nodeList[i][m_attribute] = true;
        }
        function TimeoutProcess()
        {
            if (!m_callback)
                return;
            var nodeList = observeTag ? document.getElementsByTagName(observeTag) : document.getElementsByTagName("*");
            if (nodeList.length !== m_tagCount || IsChangesOccure(nodeList))
            {
                FillTagInfo(nodeList);
                m_callback();
            }
        }
        this.Start = function(callback)
        {
            m_callback = callback;
            FillTagInfo(document.getElementsByTagName(observeTag));
            m_interval = ns.SetInterval(TimeoutProcess, 10 * 1000);
            if (document.readyState !== "complete")
                ns.AddEventListener(window, "load", TimeoutProcess);
        }
        this.Stop = function()
        {
            clearInterval(m_interval);
            m_callback = null;
        }
    }
    ns.GetDomChangeObserver = function(observeTag)
    {
        var observeTagLowerCase = observeTag ? observeTag.toLowerCase() : observeTag;
        if (window.MutationObserver && document.documentMode !== 11)    
            return new MutationChangeObserver(observeTagLowerCase);
        if (window.addEventListener)
            return new DomEventsChangeObserver(observeTagLowerCase);
        return new TimeoutChangeObserver(observeTagLowerCase);
    }
    ns.StartLocationHref = document.location.href;
    return ns;
}) (KasperskyLab || {});
(function (ns) {
    function md5cycle(x, k) {
        var a = x[0],
        b = x[1],
        c = x[2],
        d = x[3];
        a = ff(a, b, c, d, k[0], 7, -680876936);
        d = ff(d, a, b, c, k[1], 12, -389564586);
        c = ff(c, d, a, b, k[2], 17, 606105819);
        b = ff(b, c, d, a, k[3], 22, -1044525330);
        a = ff(a, b, c, d, k[4], 7, -176418897);
        d = ff(d, a, b, c, k[5], 12, 1200080426);
        c = ff(c, d, a, b, k[6], 17, -1473231341);
        b = ff(b, c, d, a, k[7], 22, -45705983);
        a = ff(a, b, c, d, k[8], 7, 1770035416);
        d = ff(d, a, b, c, k[9], 12, -1958414417);
        c = ff(c, d, a, b, k[10], 17, -42063);
        b = ff(b, c, d, a, k[11], 22, -1990404162);
        a = ff(a, b, c, d, k[12], 7, 1804603682);
        d = ff(d, a, b, c, k[13], 12, -40341101);
        c = ff(c, d, a, b, k[14], 17, -1502002290);
        b = ff(b, c, d, a, k[15], 22, 1236535329);
        a = gg(a, b, c, d, k[1], 5, -165796510);
        d = gg(d, a, b, c, k[6], 9, -1069501632);
        c = gg(c, d, a, b, k[11], 14, 643717713);
        b = gg(b, c, d, a, k[0], 20, -373897302);
        a = gg(a, b, c, d, k[5], 5, -701558691);
        d = gg(d, a, b, c, k[10], 9, 38016083);
        c = gg(c, d, a, b, k[15], 14, -660478335);
        b = gg(b, c, d, a, k[4], 20, -405537848);
        a = gg(a, b, c, d, k[9], 5, 568446438);
        d = gg(d, a, b, c, k[14], 9, -1019803690);
        c = gg(c, d, a, b, k[3], 14, -187363961);
        b = gg(b, c, d, a, k[8], 20, 1163531501);
        a = gg(a, b, c, d, k[13], 5, -1444681467);
        d = gg(d, a, b, c, k[2], 9, -51403784);
        c = gg(c, d, a, b, k[7], 14, 1735328473);
        b = gg(b, c, d, a, k[12], 20, -1926607734);
        a = hh(a, b, c, d, k[5], 4, -378558);
        d = hh(d, a, b, c, k[8], 11, -2022574463);
        c = hh(c, d, a, b, k[11], 16, 1839030562);
        b = hh(b, c, d, a, k[14], 23, -35309556);
        a = hh(a, b, c, d, k[1], 4, -1530992060);
        d = hh(d, a, b, c, k[4], 11, 1272893353);
        c = hh(c, d, a, b, k[7], 16, -155497632);
        b = hh(b, c, d, a, k[10], 23, -1094730640);
        a = hh(a, b, c, d, k[13], 4, 681279174);
        d = hh(d, a, b, c, k[0], 11, -358537222);
        c = hh(c, d, a, b, k[3], 16, -722521979);
        b = hh(b, c, d, a, k[6], 23, 76029189);
        a = hh(a, b, c, d, k[9], 4, -640364487);
        d = hh(d, a, b, c, k[12], 11, -421815835);
        c = hh(c, d, a, b, k[15], 16, 530742520);
        b = hh(b, c, d, a, k[2], 23, -995338651);
        a = ii(a, b, c, d, k[0], 6, -198630844);
        d = ii(d, a, b, c, k[7], 10, 1126891415);
        c = ii(c, d, a, b, k[14], 15, -1416354905);
        b = ii(b, c, d, a, k[5], 21, -57434055);
        a = ii(a, b, c, d, k[12], 6, 1700485571);
        d = ii(d, a, b, c, k[3], 10, -1894986606);
        c = ii(c, d, a, b, k[10], 15, -1051523);
        b = ii(b, c, d, a, k[1], 21, -2054922799);
        a = ii(a, b, c, d, k[8], 6, 1873313359);
        d = ii(d, a, b, c, k[15], 10, -30611744);
        c = ii(c, d, a, b, k[6], 15, -1560198380);
        b = ii(b, c, d, a, k[13], 21, 1309151649);
        a = ii(a, b, c, d, k[4], 6, -145523070);
        d = ii(d, a, b, c, k[11], 10, -1120210379);
        c = ii(c, d, a, b, k[2], 15, 718787259);
        b = ii(b, c, d, a, k[9], 21, -343485551);
        x[0] = add32(a, x[0]);
        x[1] = add32(b, x[1]);
        x[2] = add32(c, x[2]);
        x[3] = add32(d, x[3]);
    }
    function cmn(q, a, b, x, s, t) {
        a = add32(add32(a, q), add32(x, t));
        return add32((a << s) | (a >>> (32 - s)), b);
    }
    function ff(a, b, c, d, x, s, t) {
        return cmn((b & c) | ((~b) & d), a, b, x, s, t);
    }
    function gg(a, b, c, d, x, s, t) {
        return cmn((b & d) | (c & (~d)), a, b, x, s, t);
    }
    function hh(a, b, c, d, x, s, t) {
        return cmn(b^c^d, a, b, x, s, t);
    }
    function ii(a, b, c, d, x, s, t) {
        return cmn(c^(b | (~d)), a, b, x, s, t);
    }
    function md51(s) {
        var n = s.length,
        state = [1732584193, -271733879, -1732584194, 271733878],
        i;
        for (i = 64; i <= s.length; i += 64) {
            md5cycle(state, md5blk(s.substring(i - 64, i)));
        }
        s = s.substring(i - 64);
        var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        for (i = 0; i < s.length; i++)
            tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
        tail[i >> 2] |= 0x80 << ((i % 4) << 3);
        if (i > 55) {
            md5cycle(state, tail);
            for (i = 0; i < 16; i++)
                tail[i] = 0;
        }
        tail[14] = n * 8;
        md5cycle(state, tail);
        return state;
    }
    function md5blk(s) {
        var md5blks = [],
        i;
        for (i = 0; i < 64; i += 4) {
            md5blks[i >> 2] = s.charCodeAt(i) +
                 (s.charCodeAt(i + 1) << 8) +
                 (s.charCodeAt(i + 2) << 16) +
                 (s.charCodeAt(i + 3) << 24);
        }
        return md5blks;
    }
    var hex_chr = '0123456789abcdef'.split('');
    function rhex(n) {
        var s = '',
        j = 0;
        for (; j < 4; j++)
            s += hex_chr[(n >> (j * 8 + 4)) & 0x0F]+hex_chr[(n >> (j * 8)) & 0x0F];
        return s;
    }
    function hex(x) {
        for (var i = 0; i < x.length; i++)
            x[i] = rhex(x[i]);
        return x.join('');
    }
    ns.md5 = function (s) {
        return hex(md51(s));
    };
    function add32(a, b) {
        return (a + b) & 0xFFFFFFFF;
    }
    if (ns.md5('hello') != '5d41402abc4b2a76b9719d911017c592') {
        add32 = function(x, y) {
            var lsw = (x & 0xFFFF) + (y & 0xFFFF),
            msw = (x >> 16) + (y >> 16) + (lsw >> 16);
            return (msw << 16) | (lsw & 0xFFFF);
        }
    }
})(KasperskyLab || {});
var KasperskyLab = (function ( ns) {
ns.NMSTransportSupported = false;
return ns;
}) (KasperskyLab || {});
var KasperskyLab = (function (ns)
{
ns.AjaxTransportSupported = true;
var ajaxRequestProvider = (function ()
    {
        var oldOpen = window.XMLHttpRequest && window.XMLHttpRequest.prototype.open;
        var oldSend = window.XMLHttpRequest && window.XMLHttpRequest.prototype.send;
        var oldXHR = window.XMLHttpRequest;
        var oldXDR = window.XDomainRequest;
        return {
            GetAsyncRequest: function ()
                {
                    var xmlhttp = oldXDR ? new oldXDR() : new oldXHR();
                    if (!oldXDR) {
                        xmlhttp.open = oldOpen;
                        xmlhttp.send = oldSend;
                    }
                    xmlhttp.onprogress = function(){};
                    return xmlhttp;
                },
            GetSyncRequest: function ()
                {
                    var xmlhttp = new oldXHR();
                    xmlhttp.open = oldOpen;
                    xmlhttp.send = oldSend;
                    xmlhttp.onprogress = function(){};
                    return xmlhttp;
                }
        };
    })();
var restoreSessionCallback = function(){};
var PingPongCallReceiver = function(caller)
{
    var m_caller = caller;
    var m_isProductConnected = false;
    var m_pingWaitResponse = false;
    var m_requestDelay = ns.MaxRequestDelay;
    var m_requestTimer = null;
    var m_callCallback = function(){};
    var m_errorCallback = function(){};
    var m_updateCallback = function(){};
    function SendRequest()
    {
        try 
        {
            m_caller.Call(
                "from",
                null,
                null,
                 true,
                function(result, parameters, method)
                {
                    m_pingWaitResponse = false;
                    m_isProductConnected = true;
                    if (parameters === "undefined" || method === "undefined") 
                    {
                        m_errorCallback('AJAX pong is not received. Product is deactivated');
                        return;
                    }
                    if (method)
                    {
                        ns.SetTimeout(function () { SendRequest(); }, 0);
                        m_callCallback(method, parameters);
                    }
                },
                function(error)
                {
                    m_pingWaitResponse = false;
                    m_isProductConnected = false;
                    restoreSessionCallback();
                    m_errorCallback(error);
                });
            m_pingWaitResponse = true;
        }
        catch (e)
        {
            m_errorCallback('Ajax send ping exception: ' + (e.message || e));
        }
    }
    function Ping()
    {
        try
        {
            if (m_pingWaitResponse)
            {
                m_requestTimer = ns.SetTimeout(Ping, 100);
                return;
            }
            m_requestDelay = m_updateCallback();
            SendRequest();
            m_requestTimer = ns.SetTimeout(Ping, m_requestDelay);
        }
        catch (e)
        {
            m_errorCallback('Send ping request: ' + (e.message || e));
        }
    }
    this.StartReceive = function(callCallback, errorCallback, updateCallback)
    {
        m_isProductConnected = true;
        m_callCallback = callCallback;
        m_errorCallback = errorCallback;
        m_updateCallback = updateCallback;
        m_requestDelay = m_updateCallback();
        m_requestTimer = ns.SetTimeout(Ping, m_requestDelay);
    };
    this.ForceReceive = function()
    {
        clearTimeout(m_requestTimer);
        m_requestTimer = ns.SetTimeout(Ping, 0);
    }
    this.StopReceive = function()
    {
        clearTimeout(m_requestTimer);
        m_requestTimer = null;
        m_callCallback = function(){};
        m_errorCallback = function(){};
        m_updateCallback = function(){};
    };
    this.IsStarted = function()
    {
        return m_requestTimer !== null;
    }
    this.IsProductConnected = function()
    {
        return m_isProductConnected;
    };
};
var LongPoolingReceiver = function(caller)
{
    var m_caller = caller;
    var m_isProductConnected = false;
    var m_isStarted = false;
    var m_callCallback = function(){};
    var m_errorCallback = function(){};
    function SendRequest()
    {
        try 
        {
            m_isProductConnected = true;
            m_caller.Call(
                "longpooling",
                null,
                null,
                 true,
                OnResponse,
                function(error)
                {
                    m_isProductConnected = false;
                    restoreSessionCallback();
                    m_errorCallback(error);
                },
                true);
        }
        catch (e)
        {
            ns.SessionError(e, "ajax");
            m_errorCallback("Ajax send ping exception: " + (e.message || e));
        }
    }
    function OnResponse(result, parameters, method)
    {
        if (!ns.IsDefined(parameters) || !ns.IsDefined(method))
        {
            m_errorCallback('AJAX pong is not received. Product is deactivated');
            return;
        }
        ns.SetTimeout(function () { SendRequest(); }, 0);
        if (method)
            m_callCallback(method, parameters);
    }
    this.StartReceive = function(callCallback, errorCallback)
    {
        m_isStarted = true;
        m_callCallback = callCallback;
        m_errorCallback = errorCallback;
        SendRequest();
    };
    this.ForceReceive = function(){}
    this.StopReceive = function()
    {
        m_isStarted = false;
        m_callCallback = function(){};
        m_errorCallback = function(){};
    };
    this.IsStarted = function()
    {
        return m_isStarted;
    }
    this.IsProductConnected = function()
    {
        return m_isProductConnected;
    };
};
ns.AjaxCaller = function()
{
    var m_path = ns.GetBaseUrl() + ns.SIGNATURE;
    var m_longPooling;
    var m_longPoolingRequest;
    function NoCacheParameter() 
    {
        return "&nocache=" + Math.floor((1 + Math.random()) * 0x10000).toString(16);
    }
    function GetEncodedPluginsParameter(injectors) 
    {
        return (injectors) ? "&plugins=" + encodeURIComponent(injectors) : "";
    }
    function PrepareRequestObject(command, commandAttribute, isPost, isAsync)
    {
        var request = isAsync ? ajaxRequestProvider.GetAsyncRequest() : ajaxRequestProvider.GetSyncRequest();
        if (request)
        {
            var urlPath = m_path + "/" + command;
            if (commandAttribute)
                urlPath += "/" + commandAttribute;
            if (isPost)
            {
                request.open("POST", urlPath);
            }
            else
   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 聲明 本文章中所有內容僅供學習交流,抓包內容、敏感網址、數據介面均已做脫敏處理,嚴禁用於商業用途和非法用途,否則由此產生的一切後果均與作者無關,若有侵權,請聯繫我立即刪除! 本文章未經許可禁止轉載,禁止任何修改後二次傳播,擅自使用本文講解的技術而導致的任何意外,作者均不負責,若有侵權,請在公眾號【K ...
  • hello,大家好呀,我是小樓。 上篇文章《一言不合就重構》 說了我最近重構的一個系統,雖然重構完了,但還在灰度,這不,在灰度過程中又發現了一個問題。 背景 這個問題簡單說一下背景,如果不明白可以看上篇文章 ,不想看也沒關係,這是個通用的解法,後面我會總結抽象下。 在上篇文章的最後提到對每個摘除的地 ...
  • 摘要:本文我們就結合案常式序來說明Java記憶體模型中的Happens-Before原則。 本文分享自華為雲社區《【高併發】一文秒懂Happens-Before原則》,作者: 冰 河。 在正式介紹Happens-Before原則之前,我們先來看一段代碼。 【示例一】 class VolatileExa ...
  • 電腦誕生以來,為適應程式不斷增長的複雜過程,程式設計方法論發生了巨大變化。例如,在電腦發展初期,程式設計是通過輸入二進位機器指令來完成的。在程式僅限於幾百條指令的情況下,這種方法是可接受的。隨著程式規模的增長,人們發明瞭彙編語言,這樣程式員就可以使用代表機器指令的符號表示法來處理大型的、複雜的程 ...
  • 1、認識SpringMVC 1、什麼是MVC MVC是一種軟體架構的思想,將軟體按照模型、視圖、控制器來劃分 M:Model,模型層,指工程中的JavaBean,作用是處理數據 JavaBean分為兩類: 一類稱為實體類Bean:專門存儲業務數據的,如 Student、User 等 一類稱為業務處理 ...
  • 前言 在學習《Python從入門到精通(第2版)》的第15章 GUI界面編程——15.2.4 將.ui文件轉換為.py文件時,按照書中步驟出錯時的問題解決,希望對同樣學習本書的同學有所幫助。 問題 問題出現 當跟著書15.2.4執行步驟(2)時PyCharm報錯 錯誤提示:pyuic5: error ...
  • 上一篇文章中我們聊了Caffeine的同步、非同步的數據回源方式。本篇文章我們再一起研討下經Caffeine改良過的非同步數據驅逐處理實現,以及Caffeine支持的多種不同的數據淘汰驅逐機制和對應的實際使用。 ...
  • 1.準備 先從github官網上clone elasticsearch源碼到本地,選擇合適的分支。筆者這裡選用的是7.4.0(與筆者工作環境使用的分支一致),此版本編譯需要jdk11。 2.編譯 Readme 中說明瞭編譯命令 ./gradlew assemble 執行此命令,等待1h左右即可,根據 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...