Recommander:
This script implements a simple Web and MySQL based chat system. Simple chat script is an Open Source PHP chat script.
It generates HTML and JavaScript to display a chat box and a form input to submit new chat line entries using AJAX to avoid page reloading.
A script receives the new chat lines and stores them in a MySQL database. It also returns all the latest chat lines to display.
<?php
02 /****
03 File name : class.Chat.php
04 Description : Class for create simple chat.
05 Author : Petr Rezac
06 Date : 12th May 2010
07 Version : 1.0
08 Copyright (c) 2010 PR-Software <hide@address.com>
09 ****/
10 class Chat{
11 var $userName; // input data
12 function createChat($username){
13 if ($username=="") $username='JmÚno/Name';
14 print "<script type=\"text/javascript\">
15 function send(){
16 if ((document.getElementById('chatname').value=='')||(document.getElementById('chatname').value=='JmÚno/Name')) {
17 alert(\"NapiÜ svoje jmÚno.\\nType you name here.\");
18 document.getElementById('chatname').focus();
19 }else{
20 document.getElementById('chatop').value = 'insert';
21 ajax();
22 document.getElementById('chattext').value = '';
23 document.getElementById('chattext').focus();
24 }
25 }
26
27 function ajax() {
28 document.getElementById('chatbox').innerHTML = 'odesÝlßnÝ/sending...';
29 var chat = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject(\"Microsoft.XMLHTTP\") : false));
30 if(!chat){
31 ret='Chyba/Error JavaScript!!!';
32 }else{
33 chat.open(\"POST\", \"chat.php\", false);
34 chat.setRequestHeader(\"Content-Type\", \"application/x-www-form-urlencoded\");
35 chat.send(\"color=\"+document.getElementById('chatcolor').value+\"&name=\"+document.getElementById('chatname').value+\"&text=\"+document.getElementById('chattext').value+\"&op=\"+document.getElementById('chatop').value);
36 if (chat.readyState == 4){ //has been respond
37 if(chat.status == 200 || chat.status==0){
38 ret=chat.responseText;
39 }else{
40 ret=\"Chyba/Error!!!\"+ chat.status +\":\"+ chat.statusText;
41 }
42 }
43 }
44 document.getElementById('chatbox').innerHTML = ret;
45 document.getElementById('chatop').value = 'refresh';
46 setTimeout(\"ajax()\", 20000);
47 }
48
49 window.onload=function(){
50 setTimeout(\"ajax()\", 1000);
51 }
52 </script>";
53 print "<table width=\"340px\" style=\"border: 1px solid #7E7E81;\"><tr style=\"color:orange;font-weight: bold;background-color:#A5006F;\"><td align=\"left\">Chat</td></tr><tr><td align=\"center\">";
54 print "<div style=\"height:200px;overflow:auto;\" id=\"chatbox\" name=\"chatbox\"></div></td></tr><tr style=\"background-color:#cccccc;\"><td align=\"center\" valign=\"top\">";
55 print "<input type=\"hidden\" name=\"chatop\" id=\"chatop\" value=\"refresh\">";
56 print "<input style=\"width:80px;font:bold 10px Tahoma; padding:0;background:#f2feff;\" maxlength=\"12\" title=\"JmÚno/Name\" type=\"text\" name=\"chatname\" id=\"chatname\" value=\"$username\">";
57 print "<input style=\"width:150px;font:bold 10px Tahoma; padding:0;background:#f2feff;\" title=\"Text\" type=\"text\" name=\"chattext\" id=\"chattext\">";
58 print "<select style=\"width:50px;font:bold 10px Tahoma; padding:0;background:#f2feff;\" title=\"Barva textu/Text color\" name=\"chatcolor\" id=\"chatcolor\"><option value=\"#ff6666\">red</option><option value=\"#6699ff\">blue</option><option value=\"#99cc66\">green</option><option value=\"#ffff99\">yelow</option><option value=\"#ff6600\">orange</option></select>";
59 print "<input style=\"width:16px;height:16px;font:bold 10px Tahoma;background-color:transparent;background:#A5006F;\" title=\"OdeÜli/Send\" type=\"button\" value=\">\" onclick=\"send();\">";
60 print "</td></tr></table>";
61 }
62 }
63 ?>
More php chat sripts listed on the site Publicité supprimée
Modération CCM