PHP + ajax chat room source code! Supports long-polling and timed requests

Source: Internet
Author: User
Tags ajax chat


 

 

 

 

LastID = "1"; isposted = mGetTime; (str) {str. replace (/(^ \ s *) | (\ s * $)/g, "str = UE. getEditor ('myeditor '). str = $ ('# mess '). UE. getEditor ('myeditor '). setContent ('', _ getArgs (name, jsFileName = rName = RegExp (jsFileName + "(\\? (.*))? $ "Jss = document. getElementsByTagName ('script' (I = 0; I <jss. length; I ++ j = (j. src & j. src. oo = j. src. match (rName) [2 (oo & (t = oo. match (/([^ & =] +) = ([^ = &] +)/(l = 0; l <t. length; l ++ r = tt = r. match (/([^ & =] +) = ([^ = &] +)/userid1 = $ ('# userid1 '). (userid1 = 'Everybody 'alert (' select the chat object! \ N click the user name! '$ ("# Userid2"). attr ("checked", (name. length> 1 & name! = "All" $ ("# userto "). $ ("# userid1 "). attr ("checked", $ ("# userid2 "). attr ("checked", (name. length> 8 new_name = name. (0, 6} new_name = document. getElementById ("tousertitle "). innerHTML = "<font color = # ff6600 title =" + new_name + ">" + new_name + "</font>" }$ ("# userto "). val ("all" $ ("# userid1 "). attr ("checked", $ ("# userid2 "). attr ("checked", document. getElementById ("tousertitle "). innerHTML = "user" messval Ue = $ ("# mess"). messvalue = (messvalue. length> 650 alert ?!, Let's talk about it! \ N copied text! Clear the format first! "($ (" # Mess "2.16.html (). length <2 alert (" tip for interaction: \ n enter the content you want to post. The length must be 2 ~ 250 bytes! "D = username = $ (" # username "). userto = $ ("# userto "). userid = $ ("# userid "). mess = userpid = $ ("# userpid "). IP = $ ("# IP "). usertype = $ ("# usertype "). sendUrl = "username =" + username + "& userto =" + userto + "& userid =" + userid + "& userpid =" + userpid + "& mess =" + mess + "& IP =" + IP + "& usertype =" + usertype + "& d =" + d. sendUrl = XMLHttp. sendReq ('post', 'Send. php', sendUrl, response = obj. (response = 'OK '(! Isposted = setContentmess (); (response = 'false' alert ("failed to send! Your character contains invalid characters "d = getUrl =" getmess. php? Lastid = "+ lastID +" & numbermess = 80 & d = "+ d. getTime (); $. type: "GET", dataType: "xml", url: getUrl, async:, timeout: 80000, success :( data, isposted = chatEL = $ ("# chat" $ (data ). find ("message "). (I, sid = $ (this ). find ("sid "). succ = $ (this ). find ("succ "). umax = $ (this ). find ("umax "). user = $ (this ). find ("user "). userto = $ (this ). find ("userto "). userid = $ (this ). find ("userid "). usersex = $ (this ). find ("usersex "). us Ertype = $ (this ). find ("usertype "). userpic = $ (this ). find ("userpic "). userpid = $ (this ). find ("userpid "). text = $ (this ). find ("text "). = $ (this ). find ("date "). uid = _ getArgs ('function. js ', '2' (succ = 1 (uid> = 98 delhtml = '<a href = "#" id = "delmess" onclick = delmess ("' + sid + '", "delmess");> [delete] </a> <a href = "#" onclick = delmess ("'+ userid +'", "delusermess "); id = "delusermess"> [delete all user information] </a> '} delhtml = ''(userty Pe> = 98 chatELinnerHTML = '<div class = chu> <ul> <li class = chu1> <a href = http://www.0917cc.com? ID = '+ userid + 'target = _ blank>  </a> </li> <li class = chu2> <a href = http://www.0917cc.com? ID = '+ userid +' target = _ blank>  </a> <a href = javascript: void (0) onclick = getFirend ("'+ user +'");> <font class = ChatFont3> Administrator ('+ user + ') </font> </a>  <a href = javascript: void (0) onclick = getFirend ("'+ userto +'");> <font class = ChatFont3> '+ userto +' </font> </a> <font color = #575D69> description </font> <font col Or = #575D69> '+ +' </font>  '+ delhtml +' <br>' + text + '</li> </ul> </div> 'chatel .} chatELinnerHTML = '<div class = chu> <ul> <li class = chu1> <a href = "#" target = _ blank>  </a> </li> <li class = chu2> <a href = http://www.0917cc.com? ID = '+ userid +' target = _ blank>  </a> <a href = javascript: void (0) onclick = getFirend ("'+ user +'");> <font class = ChatFont1> ('+ user + ') </font> </a>  <a href = javascript: void (0) onclick = getFirend ("'+ userto +'");> <font class = ChatFont2> '+ userto +' </font> </a> <font color = #575D69> description </font> <font color = #575D69> '+ +' </font> '+ delhtml +' <br> '+ text +' </li> </ul> </div> 'chatel. lastID = umax; chatEL. scrollTop (document. getElementById ("chat "). scrollHeight );(! Isposted = (succ = 0 lastID = sid; chatEL. scrollTop = chatEL. scrollHeight ;(! Isposted =}, error :( XMLHttpRequest, textStatus, (textStatus = "timeout" $ ("# msg" ).show().html ("You haven't spoken for a long time. "). fadeOut (3200 (! Isposted =}

 

 

* This chat system is developed using PHP + AJAX + MYSQL! The Database supports mysql, XML, txt, accsess, and other databases, and can be converted at will.
Chat function: 1: expression 2: hyperlink 3: Send picture, 4 send file, 5 font settings, 6 graffiti Function
Function: you can speak to or to anyone, and support private chat (vip)
Support for PHP persistent connection sleep Implementation of chat room source code and ajax Implementation of chat room code
Author: margin (qq: 249189520 ---- qq group: 90316079 ----- account 1: admin Password: admin account 2: demo password: demo

Http://www.0917cc.com

PHP + ajax chat room simulation push http://room.0917y.com/websystems/Chatroom2/

You can view the differences between the connection process and the following in Firefox FF.
PHP + ajax chatroom http://room.0917y.com/websystems/Chatroom/index.php? Pid = 25 & ppid = 64

* Simulated push is implemented based on the PHP persistent connection sleep.

Disadvantages:
I have been confused all the time. The problem I haven't solved all night is that the first space to be inserted at the beginning of the editor! Error always prompted! It seems to be related to the XML specification!
It seems that c2a0 will become garbled characters in the space obtained by the ueditor. In this case, \ u00a0 does not know how to handle this problem.
The server cannot be filtered! The customer's filtering is not good yet! Please check out ....

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.