A Few Questions... |
A Few Questions... |
Nicholas_Roge |
Aug 4 2009, 03:10 PM
Post
#1
|
Group: Members Posts: 2 Joined: 4-August 09 Member No.: 9,325 |
I am trying to create a chatbox, but I've run into three problems that I really need help with.
Before I begin, here's the code I'm currently using (note that some of it is nonfunctional (namely the users column)). It should be noted that I'm using some of the MyBB functions and that one of my questions deals with server side code: chatBox.php: CODE <?php define('THIS_SCRIPT', 'chatBox.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The Digital Resarch Project - {ChatBox}</title> </head> <script type="text/javascript"> var xmlhttp; var timeout; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your browser does not support XMLHTTP!"); } function loadLogin(){ xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState==4) { document.getElementById('loginBox').innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET", "chatBoxFunctions.php?action=recieve",true); xmlhttp.send(null); } function recieveData() { xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { document.getElementById('chatText').innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET", "chatBoxFunctions.php?action=recieve", true); xmlhttp.send(null); timeout = setTimeout("recieveData()", 2000); } function sendData() { if(document.chatbox.message.value!=""){ xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { document.chatbox.message.value=""; } } xmlhttp.open("GET","chatBoxFunctions.php?action=sending&message="+document.chatbox.message.value,true); xmlhttp.send(null); }else{ alert('The message box cannot be left blank'); } } </script> <style type="text/css"> body{ margin:0; } #chatHolder.td,#chatHolder.tr{ margin:0; } #chatText{ height:400px; width:600px; overflow:scroll; } </style> <body onload="recieveData();loadLogin();"> <form name="chatbox"> <table cellspacing="0" cellpadding="0" width="100%" id="chatHolder"> <tr id="chatHeader"> <td colspan="2" width="600" align="center"><strong>The Official DRP Chat</strong></td> <td width="100px" align="center"><strong>Users</strong></td> </tr> <tr id="textAreas"> <td colspan="2"><div id="chatText"></div></td> <td id="userTextHolder"><textarea name="userText" rows="20" disable="disabled" style="width:100%">USERS</textarea></td> </tr> <tr> <td id="messageArea" align="center"><textarea name="message" rows="4" style="width:90%" onkeydown="checkKey()"></textarea><br /> <input type="button" value="Submit" onclick="sendData()"/></td> <td id="volume" width="1px" valign="bottom" align="center"><input name="muteCheckbox" type="checkbox" /><br />Mute</td> <td id="loginBox"></td> </tr> </table> </form> </body> </html> chatBoxFunctions.php: CODE <?php define('IN_MYBB', 1); define('THIS_SCRIPT', 'index.php'); require_once "./global.php"; if($_GET['action']=='sending'){ for($i=0;$i<strlen($_GET['message']);$i++){ if(substr($_GET['message'],$i,1)=="<"){ $userData['message'] .= "<"; }else if(substr($_GET['message'],$i,1)==">"){ $userData['message'] .= ">"; }else if(substr($_GET['message'],$i,1)=="\""){ $userData['message'] .= """; }else if(substr($_GET['message'],$i,1)=="'"){ $userData['message'] .= "’"; }else if(substr($_GET['message'],$i,1)=="\\"){ $userData['message'] .= "⁄"; }else if(substr($_GET['message'],$i,2)==" "){ $userData['message'] .= " "; }else{ $userData['message'] .= substr($_GET['message'],$i,1); } } $userData['uid']=$mybb->user['uid']; $query=$db->fetch_array($db->query("SELECT username FROM mybb_users WHERE uid=".$userData['uid'])); $userData['username']=$query['username']; $userData['datePosted']= time(); $db->query("INSERT INTO chatLog (message,poster,name,datePosted) VALUES ('".$userData['message']."',".$mybb->user['uid'].",'".$userData['username']."',".$userData['datePosted'].")" ); echo "Message Submitted"; } if($_GET['action']=='recieve'){ $i=1; $timeNow = time(); $query = $db->query("Select * FROM chatLog WHERE datePosted<".$timeNow." ORDER BY clid DESC Limit 0,100"); if($query){ $responce=""; while($values = $db->fetch_array($query)){ if(substr($values['message'],0,4)=="/me "){ if($i==1){ $response.="<strong>".$values['name']."</strong> ".substr($values['message'],4)."<br /><br />"; }else{ $response.="<strong>".$values['name']."</strong> ".substr($values['message'],4)."<br/>"; } }else{ if($i==1){ $response.="<strong>".$values['name']."</strong> says: ".$values['message']."<br /><br />"; }else{ $response.="<strong>".$values['name']."</strong> says: ".$values['message']."<br/>"; } } $i++; } echo $response; } } ?> _____________________________________ So on to the problems in order of severity:
And before someone says it, I've already tried google. |
Lo-Fi Version | Time is now: 26th April 2024 - 03:24 AM |