login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > Overige > AJAX > Chatbox

Chatbox

Auteur: barry - 24 december 2005 - 19:21 - Gekeurd door: nemesiskoen - Hits: 13864 - Aantal punten: 4.32 (14 stemmen)





Hier een chatbox geprogrammeerd met de AJAX-technologie (Asynchronous JavaScript and XML).

De installatie werkt als volgd:

Maak de volgende tabellen aan in een MySQL database:

  1. CREATE TABLE `users` (
  2. `id` INT(11) NOT NULL AUTO_INCREMENT,
  3. `name` VARCHAR(18) COLLATE latin1_general_ci NOT NULL DEFAULT '',
  4. `date` DECIMAL(25,0) NOT NULL DEFAULT '0',
  5. `color` VARCHAR(7) COLLATE latin1_general_ci NOT NULL DEFAULT '#000000',
  6. PRIMARY KEY (`id`),
  7. KEY `name` (`name`,`date`),
  8. KEY `color` (`color`)
  9. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=403 ;


  1. CREATE TABLE `msgs` (
  2. `id` INT(11) NOT NULL AUTO_INCREMENT,
  3. `who` VARCHAR(18) COLLATE latin1_general_ci NOT NULL DEFAULT '',
  4. `color` VARCHAR(7) COLLATE latin1_general_ci NOT NULL DEFAULT '#000000',
  5. `msg` VARCHAR(255) COLLATE latin1_general_ci NOT NULL DEFAULT '',
  6. `type` ENUM('msg','info','logoff','logon') COLLATE latin1_general_ci NOT NULL DEFAULT 'msg',
  7. `date` DECIMAL(25,0) NOT NULL DEFAULT '0',
  8. PRIMARY KEY (`id`),
  9. KEY `who` (`who`,`color`,`msg`,`type`,`date`)
  10. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2967 ;


De enige benodigde bestanden zijn index.php en server.php.

Ook heeft het script de optie om smileys te gebruiken, hiervoor kun je de smileys downloaden van: http://files.dsound.nl/smileys.rar

Het script heeft wel zijn mankementen,
in sommige browsers zal het lijken voor de gebruiker dat zijn berichten dubbel gepost worden, dit zien anderen echter niet.

Ook, omdat het script feitelijk constant server.php opnieuw inlaad, zullen sommige browsers in de statusbalk aangeven dat de website nog geladen wordt.

Verder is het een goed werken script, maar onzeker is of dit wel de ideale manier is om een chatbox te maken.

AJAX biedt namelijk veel meer mogelijkheden met zijn functionaliteiten, denk maar aan Googlemaps en Gmail, welke ook met de AJAX-technologie zijn geprogrammeerd.

Allereerst hier mijn chatbox:

Code:
index.php
  1. <?
  2. mysql_connect("localhost", "****", "****");
  3. mysql_select_db("****");
  4.  
  5. function authUser($name) {
  6. mysql_query("INSERT INTO `users` VALUES ('', '".$name."', '".mktime()."', '#000000 ');");
  7. $r = mysql_query("SELECT * FROM `users` WHERE `name` = '".$name."'");
  8. $a = mysql_fetch_array($r, MYSQL_ASSOC);
  9. $_SESSION['userId'] = $a['id'];
  10. $_SESSION['name'] = $name;
  11. }
  12.  
  13. if ($_POST['username']) {
  14. $r = mysql_query("SELECT * FROM `users` WHERE `name` = '".$_POST['username']."'");
  15.  
  16. if (mysql_num_rows($r) == 0) {
  17. authUser($_POST['username']);
  18. }
  19.  
  20. else {
  21. header("location: index.php?msg=UserExists");
  22. }
  23.  
  24. }
  25. ?>
  26. <html>
  27. <head>
  28. <title>Chatbox<?=($_SESSION['name']) ? ' ('.$_SESSION['name'].')' : '';?></title>
  29.  
  30. <style type="text/css">
  31.  
  32. body, td, th {
  33. font-family: Arial, Helvetica, sans-serif;
  34. font-size: 12px;
  35. color: #000000;
  36. }
  37.  
  38. a:link, a:visited, a:active {
  39. color: #333333;
  40. text-decoration: underline;
  41. }
  42.  
  43. a:hover {
  44. text-decoration: none;
  45. color: #003399;
  46. }
  47.  
  48. #chatframe, #chatters {
  49. height: 384px;
  50. background-color: #DEDEDE;
  51. border: 1px #000000 solid;
  52. overflow: auto;
  53. text-align: left;
  54. padding: 2px;
  55. word-spacing: inherit;
  56. }
  57.  
  58. input {
  59. background-color: #EEEEEE;
  60. border: 1px #000000 solid;
  61. height: 22px;
  62. }
  63.  
  64. #chatbox {
  65. border: 1px #000000 solid;
  66. background-color: #B5AE9B;
  67. }
  68.  
  69. #chatbox td {
  70. vertical-align: top;
  71. text-align: left;
  72. padding: 8px;
  73. }
  74. </style>
  75.  
  76. <script>
  77. <?
  78. echo ($_SESSION['name']) ? 'timertje = setTimeout("chat()",400)'."\n" : '';
  79. ?>
  80. function xmlHttpGo(div, url) {
  81. var w3c = (typeof window.XMLHttpRequest != 'undefined');
  82. var ie = (typeof window.ActiveXObject != 'undefined');
  83.  
  84. if (w3c) {
  85. var xmlHttp = new XMLHttpRequest();
  86. }
  87. else if (ie) {
  88. var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  89. }
  90. else {
  91. return false;
  92. }
  93.  
  94. xmlHttp.open("GET", url, true);
  95. xmlHttp.onreadystatechange = function() {
  96. if (xmlHttp.readyState == 4) {
  97. alertRoot(xmlHttp);
  98. }
  99. }
  100. xmlHttp.send(null);
  101.  
  102. function alertRoot(xmlHttp) {
  103. if (div == 'chatters') {
  104. var txt = xmlHttp.responseText
  105. document.getElementById(div).innerHTML = txt;
  106. }
  107. else {
  108. var txt = xmlHttp.responseText
  109. var lastxt = document.getElementById("last");
  110. if (txt != lastxt.value) {
  111. document.getElementById(div).innerHTML += txt;
  112. }
  113. lastxt.value = txt;
  114. }
  115. }
  116. }
  117.  
  118. function users() {
  119. var d = new Date();
  120. url = 'server.php?get=users&random='+d.getFullYear()+(d.getMonth()+1)+d.getDate()+d.getHours()+d.getMinutes()+d.getSeconds()
  121. xmlHttpGo('chatters', url, false)
  122. document.getElementById('chatframe').scrollTop = 10000000;
  123. window.setTimeout("users()",2000)
  124. }
  125.  
  126. function chatadd(type) {
  127. var d = new Date();
  128. var randomU = d.getFullYear()+(d.getMonth()+1)+d.getDate()+d.getHours()+d.getMinutes()+d.getSeconds()
  129.  
  130. if (type == 'logon') {
  131. var url = 'server.php?msg=&type=logon&u=<?=$_SESSION['userId'];?>&random='+randomU
  132. }
  133. else if (type == 'logoff') {
  134. var url = 'server.php?msg=&type=logoff&u=<?=$_SESSION['userId'];?>&random='+randomU
  135. }
  136. else {
  137. var url = 'server.php?msg='+document.getElementById("msg").value+'&type=msg&u=<?=$_SESSION['userId'];?>&random='+randomU
  138. }
  139.  
  140. xmlHttpGo('chatframe', url)
  141. document.getElementById("msg").value = '';
  142. document.getElementById('chatframe').scrollTop = 10000000;
  143. clearTimeout(timertje)
  144. chat();
  145. return (false);
  146. }
  147.  
  148. function chat() {
  149. var d = new Date();
  150. var randomU = d.getFullYear()+(d.getMonth()+1)+d.getDate()+d.getHours()+d.getMinutes()+d.getSeconds()
  151. xmlHttpGo('chatframe', 'server.php?msg=&random='+randomU)
  152. timertje = setTimeout("chat()",400)
  153. document.getElementById('chatframe').scrollTop = 10000000;
  154. window.status = 'Chatbox...';
  155. }
  156. </script>
  157.  
  158. </head>
  159.  
  160. <?
  161. if ($_SESSION['name']) {
  162. echo '<body onLoad="chatadd(\'logon\'); users();" onUnload="chatadd(\'logoff\');">';
  163. }
  164. else {
  165. echo '<body>';
  166. }
  167. ?>
  168.  
  169. <center>
  170. <table id="chatbox" border="0" cellspacing="0" cellpadding="0">
  171. <tr>
  172. <td width="528">
  173. <pre id="chatframe" style="width: 512px;"></pre>
  174. <?
  175. if ($_SESSION['userId']) {
  176. echo ' <form name=frm onSubmit="return chatadd(\'msg\');">
  177. <input id="msg" type="text" name="msg" style="width: 512px;">
  178. <input type="hidden" name="last" id="last" value="">
  179. </form>';
  180. }
  181.  
  182. else {
  183.  
  184. if ($_GET['msg'] == 'UserExists') {
  185. $msg = ' <br><b>Deze gebruikersnaam wordt al gebruikt... Kies een ander a.u.b.</b>';
  186. }
  187.  
  188. echo ' Please get a username first!<br>
  189. <form method=post action="">
  190. Naam: <input type="text" name="username">
  191. <input type="submit" name="submit" value="Ok">
  192. '.$msg.'
  193. </form>';
  194. }
  195. ?>
  196. </td>
  197. <td width="144">
  198. <pre id="chatters" style="width: 128px;"></pre>
  199. </td>
  200. </tr>
  201. </table>
  202. </center>
  203. </body>
  204. </html>


server.php
  1. <?
  2. mysql_connect("localhost", "****", "****");
  3. mysql_select_db("****");
  4.  
  5. define('smileyDir', 'smileys/');
  6. define('maxMsgsinDB', 70);
  7. define('delAmmountDB', 5);
  8. define('maxIdleTime', 600);
  9.  
  10. function smiley_array() {
  11. $smiley[] = array('code' => '(n)', 'image' => 'thumbdown.gif');
  12. $smiley[] = array('code' => '(N)', 'image' => 'thumbdown.gif');
  13. $smiley[] = array('code' => '(y)', 'image' => 'thumbup.gif');
  14. $smiley[] = array('code' => '(Y)', 'image' => 'thumbup.gif');
  15. $smiley[] = array('code' => ':(', 'image' => 'unhappy.gif');
  16. $smiley[] = array('code' => ':-(', 'image' => 'unhappy.gif');
  17. $smiley[] = array('code' => ':)', 'image' => 'standard.gif');
  18. $smiley[] = array('code' => ':-)', 'image' => 'standard.gif');
  19. $smiley[] = array('code' => '(k)', 'image' => 'kiss.gif');
  20. $smiley[] = array('code' => '(K)', 'image' => 'kiss.gif');
  21. $smiley[] = array('code' => '(l)', 'image' => 'love.gif');
  22. $smiley[] = array('code' => '(L)', 'image' => 'love.gif');
  23. $smiley[] = array('code' => ':lief:', 'image' => 'love.gif');
  24. $smiley[] = array('code' => ':flower:', 'image' => 'flower.gif');
  25. $smiley[] = array('code' => '(f)', 'image' => 'flower.gif');
  26. $smiley[] = array('code' => '(F)', 'image' => 'flower.gif');
  27. $smiley[] = array('code' => ':s', 'image' => 'confused.gif');
  28. $smiley[] = array('code' => ':-s', 'image' => 'confused.gif');
  29. $smiley[] = array('code' => ':S', 'image' => 'confused.gif');
  30. $smiley[] = array('code' => ':-S', 'image' => 'confused.gif');
  31. $smiley[] = array('code' => ':\\', 'image' => 'hmmz_streep.gif');
  32. $smiley[] = array('code' => ':-\\', 'image' => 'hmmz_streep.gif');
  33. $smiley[] = array('code' => ':/', 'image' => 'hmmzz_streep.gif');
  34. $smiley[] = array('code' => ':-/', 'image' => 'hmmzz_streep.gif');
  35. $smiley[] = array('code' => ':knuffel:','image' => 'hug.gif');
  36. $smiley[] = array('code' => ':kusje:', 'image' => 'kiss_2.gif');
  37. $smiley[] = array('code' => ':kus:', 'image' => 'kiss_1.gif');
  38. $smiley[] = array('code' => 'O:)', 'image' => 'hypocrite.gif');
  39. $smiley[] = array('code' => 'O:-)', 'image' => 'hypocrite.gif');
  40. $smiley[] = array('code' => ':p', 'image' => 'tongue.gif');
  41. $smiley[] = array('code' => ':-p', 'image' => 'tongue.gif');
  42. $smiley[] = array('code' => ':P', 'image' => 'tongue.gif');
  43. $smiley[] = array('code' => ':-P', 'image' => 'tongue.gif');
  44. $smiley[] = array('code' => ';p', 'image' => 'tongue_wink.gif');
  45. $smiley[] = array('code' => ';-p', 'image' => 'tongue_wink.gif');
  46. $smiley[] = array('code' => ';P', 'image' => 'tongue_wink.gif');
  47. $smiley[] = array('code' => ';-P', 'image' => 'tongue_wink.gif');
  48. $smiley[] = array('code' => ':d', 'image' => 'wide.gif');
  49. $smiley[] = array('code' => ':-d', 'image' => 'wide.gif');
  50. $smiley[] = array('code' => ':D', 'image' => 'wide.gif');
  51. $smiley[] = array('code' => ':-D', 'image' => 'wide.gif');
  52. $smiley[] = array('code' => ':x', 'image' => 'shutup.gif');
  53. $smiley[] = array('code' => ':-x', 'image' => 'shutup.gif');
  54. $smiley[] = array('code' => ':X', 'image' => 'shutup.gif');
  55. $smiley[] = array('code' => ':-X', 'image' => 'shutup.gif');
  56. $smiley[] = array('code' => ':z', 'image' => 'sleepy.gif');
  57. $smiley[] = array('code' => ':-z', 'image' => 'sleepy.gif');
  58. $smiley[] = array('code' => ':Z', 'image' => 'sleepy.gif');
  59. $smiley[] = array('code' => ':-Z', 'image' => 'sleepy.gif');
  60. $smiley[] = array('code' => '(s)', 'image' => 'sleepy.gif');
  61. $smiley[] = array('code' => '(S)', 'image' => 'sleepy.gif');
  62. $smiley[] = array('code' => '(b)', 'image' => 'beer.gif');
  63. $smiley[] = array('code' => '(B)', 'image' => 'beer.gif');
  64. $smiley[] = array('code' => ':k', 'image' => 'drool.gif');
  65. $smiley[] = array('code' => ':-k', 'image' => 'drool.gif');
  66. $smiley[] = array('code' => ':K', 'image' => 'drool.gif');
  67. $smiley[] = array('code' => ':-K', 'image' => 'drool.gif');
  68. $smiley[] = array('code' => ':kwijl:', 'image' => 'drool.gif');
  69. $smiley[] = array('code' => ':o', 'image' => 'ooo.gif');
  70. $smiley[] = array('code' => ':-o', 'image' => 'ooo.gif');
  71. $smiley[] = array('code' => ':O', 'image' => 'ooo.gif');
  72. $smiley[] = array('code' => ':-O', 'image' => 'ooo.gif');
  73. $smiley[] = array('code' => ':$', 'image' => 'bloos.gif');
  74. $smiley[] = array('code' => ':-$', 'image' => 'bloos.gif');
  75. $smiley[] = array('code' => ':bloos:', 'image' => 'bloos.gif');
  76. $smiley[] = array('code' => ':gaap:', 'image' => 'yawn.gif');
  77. $smiley[] = array('code' => ':aai:', 'image' => 'pet.gif');
  78. $smiley[] = array('code' => ':woet:', 'image' => 'poowpoow.gif');
  79. $smiley[] = array('code' => '(h)', 'image' => 'cool.gif');
  80. $smiley[] = array('code' => '(H)', 'image' => 'cool.gif');
  81. $smiley[] = array('code' => ':@', 'image' => 'angry.gif');
  82. $smiley[] = array('code' => ':-@', 'image' => 'angry.gif');
  83. $smiley[] = array('code' => ':respect:','image' => 'worshippy.gif');
  84. $smiley[] = array('code' => '_o_', 'image' => 'worshippy.gif');
  85. $smiley[] = array('code' => '_O_', 'image' => 'worshippy.gif');
  86. $smiley[] = array('code' => ';)', 'image' => 'wink.gif');
  87. $smiley[] = array('code' => ';-)', 'image' => 'wink.gif');
  88. $smiley[] = array('code' => 'O:)', 'image' => 'hypocrite.gif');
  89. $smiley[] = array('code' => 'O:-)', 'image' => 'hypocrite.gif');
  90. $smiley[] = array('code' => 'o:)', 'image' => 'hypocrite.gif');
  91. $smiley[] = array('code' => 'o:-)', 'image' => 'hypocrite.gif');
  92. $smiley[] = array('code' => '8)', 'image' => 'veryhappy.gif');
  93. $smiley[] = array('code' => '8-)', 'image' => 'veryhappy.gif');
  94. $smiley[] = array('code' => ':|', 'image' => 'hmmz.gif');
  95. $smiley[] = array('code' => ':-|', 'image' => 'hmmz.gif');
  96. $smiley[] = array('code' => ':9', 'image' => 'yummie.gif');
  97. $smiley[] = array('code' => ':-9', 'image' => 'yummie.gif');
  98. $smiley[] = array('code' => ':ja:', 'image' => 'yes_new.gif');
  99. $smiley[] = array('code' => ':nee:', 'image' => 'nooo.gif');
  100. $smiley[] = array('code' => ':yes:', 'image' => 'yes_new.gif');
  101. $smiley[] = array('code' => ':no:', 'image' => 'nooo.gif');
  102. $smiley[] = array('code' => ":'(", 'image' => 'cry.gif');
  103. $smiley[] = array('code' => ':frusty:', 'image' => 'frusty.gif');
  104.  
  105. return $smiley;
  106. }
  107.  
  108. if ($_GET['get'] == 'users') {
  109. $r = mysql_query("SELECT *FROM `users` ORDER BY `name` ASC") or die (mysql_error());
  110.  
  111. while ($a = mysql_fetch_array($r, MYSQL_ASSOC)) {
  112.  
  113. if ($a['name'] == $_SESSION['name']) {
  114. echo '<b>'.$a['name'].'</b><br>';
  115. }
  116.  
  117. else {
  118. echo $a['name'].'<br>';
  119. }
  120.  
  121. }
  122.  
  123. $status = status($_SESSION['name']);
  124. echo '<br>&nbsp;<br>&nbsp;<br>&nbsp;<br><center>Status: <b>'.$status.'</b></center>';
  125. }
  126.  
  127. function deletefirst($max, $del=1) {
  128. $r = mysql_query("SELECT * FROM `msgs`");
  129. $n = mysql_num_rows($r);
  130.  
  131. if ($n >= $max) {
  132. $q = mysql_query("SELECT `id` FROM `msgs` ORDER BY `id` LIMIT ".$del."");
  133.  
  134. while ($a = mysql_fetch_array($q, MYSQL_ASSOC)) {
  135. mysql_query("DELETE FROM `msgs` WHERE `id` = '".$a['id']."'");
  136. }
  137.  
  138. }
  139.  
  140. }
  141.  
  142. function status($username) {
  143. $d = mktime();
  144. $c = $d - maxIdleTime;
  145.  
  146. $r = mysql_query("SELECT `date` FROM `users` WHERE `name` = '".$username."'");
  147. $a = mysql_fetch_array($r, MYSQL_ASSOC);
  148.  
  149. if (mysql_num_rows($r) == 1) {
  150. return 'online';
  151. }
  152.  
  153. elseif ($a['date'] < $c) {
  154. return 'afwezig';
  155. }
  156.  
  157. else {
  158. return 'offline';
  159. }
  160. }
  161.  
  162. function remove($user) {
  163. $d = mktime();
  164. $c = $d - maxIdleTime;
  165. $r = mysql_query("SELECT * FROM `users` WHERE `name` = '".$_SESSION['name']."' AND `date` < '".$c."'");
  166.  
  167. if (mysql_num_rows($r) == 1) {
  168. addMsgInDb($_SESSION['name'], '<font color="#3B0B4F"><b>Niet meer aanwezig op de chat</b></font>', '#000000', 'msg');
  169. }
  170.  
  171. mysql_query("DELETE FROM `users` WHERE `name` = '".$user."' OR `date` < '".$c."'") or die (mysql_error());
  172. }
  173.  
  174. function update($user) {
  175. mysql_query("UPDATE `users` SET `date` = '".mktime()."' WHERE `name` = '".$user."'");
  176. }
  177.  
  178. function add($user) {
  179. $r = mysql_query("SELECT * FROM `users` WHERE `name` = '".$user."'");
  180.  
  181. if (mysql_num_rows($r) == 0) {
  182. mysql_query("INSERT INTO `users` VALUES ('', '".$user."', '".mktime()."', '#000000 ');");
  183. $r = mysql_query("SELECT * FROM `users` WHERE `name` = '".$user."'");
  184. $a = mysql_fetch_array($r, MYSQL_ASSOC);
  185. $_SESSION['userId'] = $a['id'];
  186. $_SESSION['name'] = $user;
  187. }
  188.  
  189. }
  190.  
  191. function replace_smileys($txt) {
  192. $ntxt = $txt;
  193. $arr = smiley_array();
  194.  
  195. foreach ($arr as $key => $value) {
  196. $ntxt = str_replace($value['code'], '<img src="'.smileyDir.$value['image'].'" title="'.$value['code'].'" border=0>', $ntxt);
  197. }
  198.  
  199. return $ntxt;
  200. }
  201.  
  202. function addMsgInDb($who, $msg, $color, $type) {
  203. mysql_query("INSERT INTO `msgs` VALUES ('',
  204. '".$who."',
  205. '".$color."',
  206. '".$msg."',
  207. '".$type."',
  208. '".mktime()."');") or die (mysql_error());
  209. }
  210.  
  211. function returnMsgsFromDb($id) {
  212. deletefirst(maxMsgsinDB, delAmmountDB);
  213. $r = mysql_query("SELECT * FROM `msgs` WHERE `id` >= '".$id."' ORDER BY `id` DESC LIMIT 1");
  214.  
  215. if (mysql_num_rows($r) == 0) {
  216. return '';
  217. }
  218.  
  219. else {
  220.  
  221. while($a = mysql_fetch_array($r, MYSQL_ASSOC)) {
  222.  
  223. if ($a['type'] == 'logon') {
  224. $return .= '<font color="#07368D"><b>'.$a['who'].' komt de chatroom binnen</b></font><br>';
  225. }
  226.  
  227. elseif ($a['type'] == 'logoff') {
  228. remove($a['who']);
  229. $return .= '<font color="#07368D"><b>'.$a['who'].' verlaat de chatroom</b></font><br>';
  230. }
  231.  
  232. else {
  233. $newTxt = replace_smileys($a['msg']);
  234.  
  235. if (substr($newTxt, 0, 1) == '/') {
  236.  
  237. if (substr($a['msg'], 0, 4) == '/me ') {
  238. $return .= '<font color="#9D4168">'.date("H:i:s", $a['date']).' <b>'.$a['who'].' '.str_replace("/me ", "", $newTxt).'</b></font><br>';
  239. }
  240.  
  241. elseif (substr($newTxt, 0, 3) == '/b ') {
  242. $return .= date("H:i:s", $a['date']).' <b>'.$a['who'].': <font color="'.$a['color'].'">'.str_replace("/b ", "", $newTxt).'</font></b><br>';
  243. }
  244.  
  245. elseif (substr($newTxt, 0, 3) == '/u ') {
  246. $return .= date("H:i:s", $a['date']).' <b>'.$a['who'].'</b>: <u><font color="'.$a['color'].'">'.str_replace("/u ", "", $newTxt).'</font></u><br>';
  247. }
  248.  
  249. elseif (substr($newTxt, 0, 3) == '/i ') {
  250. $return .= date("H:i:s", $a['date']).' <b>'.$a['who'].'</b>: <i><font color="'.$a['color'].'">'.str_replace("/i ", "", $newTxt).'</font></i><br>';
  251. }
  252.  
  253. elseif (substr($newTxt, 0, 8) == '/noicon ') {
  254. $return .= date("H:i:s", $a['date']).' <b>'.$a['who'].'</b>: <font color="'.$a['color'].'">'.str_replace("/noicon ", "", $newTxt).'</font><br>';
  255. }
  256.  
  257. else {
  258. $return .= date("H:i:s", $a['date']).' <b>'.$a['who'].'</b>: <font color="'.$a['color'].'">'.str_replace("/", "", $newTxt).'</font><br>';
  259. }
  260. }
  261.  
  262. else {
  263. $return .= date("H:i:s", $a['date']).' <b>'.$a['who'].'</b>: <font color="'.$a['color'].'">'.$newTxt.'</font><br>';
  264. }
  265.  
  266. }
  267.  
  268. }
  269.  
  270. return $return;
  271. }
  272.  
  273. }
  274.  
  275. $r = mysql_query("SELECT * FROM `msgs` ORDER BY `id` DESC LIMIT 1");
  276. $a = mysql_fetch_array($r, MYSQL_ASSOC);
  277.  
  278. $_SESSION['lastId'] = $a['id'];
  279. if ($_GET['type'] == 'logon') {
  280. add($_SESSION['name']);
  281. addMsgInDb($_SESSION['name'], $_GET['msg'], '#000000', $type=$_GET['type']);
  282. }
  283.  
  284. elseif ($_GET['type'] == 'logoff') {
  285. remove($_SESSION['name']);
  286. addMsgInDb($_SESSION['name'], $_GET['msg'], '#000000', $type=$_GET['type']);
  287. }
  288.  
  289. elseif ($_GET['type'] == 'msg') {
  290. add($_SESSION['name']);
  291. update($_SESSION['name']);
  292. addMsgInDb($_SESSION['name'], strip_tags($_GET['msg']), '#000000', $type=$_GET['type']);
  293. }
  294.  
  295. if ($_SESSION['userId']) {
  296. remove(md5('dezenaamwordttochnietgebruikt!!'));
  297. echo returnMsgsFromDb($_GET['li']);
  298. }
  299.  
  300. else {
  301. echo '<b>Bob</b>: No name set!<br>';
  302. }
  303.  
  304. ?>


Bovenin server.php zijn er wat constanten te veranderen, voor een functionaliteit naar wens.
Let hierbij ook de url naar de smileys.Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (29)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.116s