Questo e il codice nel file Chat.html
<!DOCTYPE html>
<html lang="it">
<head>
<title>CHAT</title>
<meta charset="UTF-8">
<link rel="icon" href="immagini/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="immagini/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href="tasti.css">
<style type="text/css">
body { padding-left:40px; background:#cccccc; font-family:arial;}
input, textarea { font-family: courier new; font-size: 12px; }
#content { background:#cccccc; width:800px; text-align:left; margin-left:60px; }
#chatwindow { border:1px solid #aaaaaa; padding:4px; background:#cccccc; color:#000000;}
#chatnick { padding:4px; background:#ffffff;}
#chatmsg { padding:4px; background:#ffffff; }
#info { text-align:left; padding-left:0px; font-family:arial; }
#info td { font-size:12px; padding-right:10px; color:#DFDFDF; }
#info .small { font-size:10px; padding-left:10px; padding-right:0px;}
#info a { text-decoration:none; color:white; }
#info a:hover { text-decoration:underline; color:#CF9700;}
</style>
</head>
<body>
<div id="content">
<br><br>
<textarea id="chatwindow" rows="15" cols="70" readonly></textarea><br>
<br><br><br>
<input id="chatnick" type="text" placeholder="Nome" size="9" maxlength="10" ><br><br>
<input id="chatmsg" type="text" placeholder="Messaggio" size="72" onkeyup="keyup(event.keyCode);">
<br><br>
<input type="button" value="Invia" class="buttonform10" onclick="submit_msg();">
<input type="button" value="Reset" class="buttonform10" onclick="cancella();">
<br><br>
<br>
</div>
</body>
</html>
<script type="text/javascript">
/* most simple ajax chat script (
www.linuxuser.a) (GPLv2) */
var nick_maxlength=10;
var http_request=false;
var http_request2=false;
var intUpdate;
/* http_request for writing */
function ajax_request(url){http_request=false;if(window.XMLHttpRequest){http_request=new XMLHttpRequest();if(http_request.overrideMimeType){http_request.overrideMimeType('text/xml');}}else if(window.ActiveXObject){try{http_request=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{http_request=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}}}
if(!http_request){alert('Giving up Cannot create an XMLHTTP instance');return false;}
http_request.onreadystatechange=alertContents;http_request.open('GET',url,true);http_request.send(null);}
function alertContents(){if(http_request.readyState==4){if(http_request.status==200){rec_response(http_request.responseText);}else{}}}
/* http_request for reading */
function ajax_request2(url){http_request2=false;if(window.XMLHttpRequest){http_request2=new XMLHttpRequest();if(http_request2.overrideMimeType){http_request2.overrideMimeType('text/xml');}}else if(window.ActiveXObject){try{http_request2=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{http_request2=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}}}
if(!http_request2){alert('Giving up Cannot create an XMLHTTP instance');return false;}
http_request2.onreadystatechange=alertContents2;http_request2.open('GET',url,true);http_request2.send(null);}
function alertContents2(){if(http_request2.readyState==4){if(http_request2.status==200){rec_chatcontent(http_request2.responseText);}else{}}}
/* chat stuff */
chatmsg.focus()
var show_newmsg_on_bottom=1; /* set to 0 to let new msg´s appear on top */
var waittime=3000; /* time between chat refreshes (ms) */
intUpdate=window.setTimeout("read_cont();", waittime);
chatwindow.value = "Benevenuto, in questa piccola chat....";
function read_cont() { zeit = new Date(); ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds(); ajax_request2("chat.txt?x=" + ms); }
function display_msg(msg1) { chatwindow.value = msg1.substr(0,msg1.length - 1); }
function keyup(arg1) { if (arg1 == 13) submit_msg(); }
function cancella(){
ajax_request("c.php");
chatwindow.value=" "; intUpdate=window.setTimeout("read_cont();", waittime);
}
function submit_msg() { clearTimeout(intUpdate); if (chatnick.value == "") { check = prompt("please enter username:"); if (check === null) return 0; if (check == "") check="..."; chatnick.value=check; } if (chatnick.value.length > nick_maxlength) chatnick.value=chatnick.value.substring(0,nick_maxlength); spaces=""; for(i=0;i<(nick_maxlength-chatnick.value.length);i++) spaces+=" "; v=chatwindow.value.substring(chatwindow.value.indexOf("\n")) + "\n" + chatnick.value + spaces + "| " + chatmsg.value; if (chatmsg.value != "") chatwindow.value=v.substring(1); write_msg(chatmsg.value,chatnick.value); chatmsg.value=""; intUpdate=window.setTimeout("read_cont();", waittime);}
function write_msg(msg1,nick1) { ajax_request("w.php?m=" + escape(msg1) + "&n=" + escape(nick1)); }
function rec_response(str1) { }
function rec_chatcontent(cont1) {
if (cont1 != "") {
out1 = unescape(cont1);
if (show_newmsg_on_bottom == 0) { out1 = ""; while (cont1.indexOf("\n") > -1) { out1 = cont1.substr(0, cont1.indexOf("\n")) + "\n" + out1; cont1 = cont1.substr(cont1.indexOf("\n") + 1); out1 = unescape(out1); } }
if (chatwindow.value != out1) { display_msg(out1); }
intUpdate=window.setTimeout("read_cont()", waittime);
}
}
</script>
Poi c'e il codice nel file w.php
<?php
/* author: chris at linuxuser.at
licence: GPLv2
*/
$fn = "chat.txt";
$maxlines = 50;
$nick_maxlength = 10;
/* Set this to a minimum wait time between posts (in sec) */
$waittime_sec = 0;
/* spam keywords */
$spam[] = "nigger";
$spam[] = "cum";
$spam[] = "dick";
$spam[] = "EAT coon";
/* IP's to block */
$blockip[] = "72.60.167.89";
/* spam, if message IS exactly that string */
$espam[] = "ajax";
$msg = $_REQUEST["m"];
$n = $_REQUEST["n"];
if ($waittime_sec > 0) {
$lastvisit = $_COOKIE["lachatlv"];
setcookie("lachatlv", time());
if ($lastvisit != "") {
$diff = time() - $lastvisit;
if ($diff < 5) { die(); }
}
}
if ($msg != "") {
if (strlen($msg) < 2) { die(); }
if (strlen($msg) > 3) {
/* Smilies are ok */
if (strtoupper($msg) == $msg) { die(); }
}
if (strlen($msg) > 1500) { die(); }
if (strlen($msg) > 15) {
//if (substr_count($msg, substr($msg, 6, ) > 1) { die(); }
}
foreach ($blockip as $a) {
if ($_SERVER["REMOTE_ADDR"] == $a) { die(); }
}
$mystring = strtoupper($msg);
foreach ($spam as $a) {
if (strpos($mystring, strtoupper($a)) === false) {
/* Everything Ok Here */
} else {
die();
}
}
foreach ($espam as $a) {
if (strtoupper($msg) == strtoupper($a)) { die(); }
}
$handle = fopen ($fn, 'r');
$chattext = fread($handle, filesize($fn)); fclose($handle);
$arr1 = explode("\n\n", $chattext);
if (count($arr1) > $maxlines) {
/* Pruning */
$arr1 = array_reverse($arr1);
for ($i=0; $i<$maxlines; $i++) { $arr2[$i] = $arr1[$i]; }
$arr2 = array_reverse($arr2);
} else {
$arr2 = $arr1;
}
$chattext = implode("\n\n", $arr2);
if (substr_count($chattext, $msg) > 2) { die(); }
$spaces = "";
if (strlen($n) > $nick_maxlength-1) $n = substr($n, 0, $nick_maxlength-1);
for ($i=0; $i<($nick_maxlength - strlen($n)); $i++) $spaces .= " ";
$out = $chattext . $n . $spaces . "| " . $msg . "\n\n";
$out = str_replace("\'", "'", $out);
$out = str_replace("\\\"", "\"", $out);
$handle = fopen ($fn, 'w'); fwrite ($handle, $out); fclose($handle);
}
?>
e infine il codice nel file c.php
<?php
/* author: chris at linuxuser.at
licence: GPLv2
*/
$fn = "chat.txt";
file_put_contents($fn, "");
?>
naturalmente rimane il file di testo chat.txt
Altro non so dirti........................ringrazio anticipatamente per qualsiasi spunto in merito....