--chatbox.html-----------------------------------------------------------------------------
[code]
<script>
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
var timer = 6000; //iedere 5 seconden refreshen

function say(value)
{
	name = document.getElementById('name').value;
	xmlhttp.open("GET", "chat.php?text="+value+"&name="+name+"&random="+Math.round(9000*Math.random()),true);//method, target, async (set always true!)
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById('chatwindow').innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.send(null);
	timer = 6000;
	counter();
}

function update()
{
	xmlhttp.open("GET", "chat.php?random="+Math.round(9000*Math.random()),true);//method, target, async (set always true!)
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById('chatwindow').innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.send(null);
	timer = 6000;
	counter();
}

function counter()
{
	if(timer == 0)
	{
		update();
	}
	else
	{
		timer = timer - 1000;
		setTimeout("counter()", 1000);
	}
}

function check_enter(eventobjekt) 
{
   //Bedankt Cees!
   var var_key;
   if (navigator.appName == "Microsoft Internet Explorer") {
      var_key = window.event.keyCode;
   } else {
      var_key = eventobjekt.which;
   }
   if (var_key==13) {//{alert(var_key);
      say(value);
      document.getElementById('chattext').value = "";
   }
}

function hasvalue(value)
{
	if(value != "")
	{
		document.getElementById('submitbutton').disabled = false;
	}
	else
	{
		document.getElementById('submitbutton').disabled = true;
	}
}
</script>
<input type="text" id="name" name="name" style="width: 600px;" maxlength="256" value="Annoniem"/>
<div id="chatwindow" style="display:block; width: 600px; height: 400px; overflow: scroll;">
	Welcome to the chat. Please type a message.
</div><br/>
<input type="text" id="chattext" name="chattext" onKeyPress="check_enter(event);hasvalue(this.value);" onChange="hasvalue(this.value);" maxlength="256" style="width: 450px; "/>
<input type="submit" id="submitbutton" onMouseDown="javascript: say(document.getElementById('chattext').value);document.getElementById('chattext').value = '';" value="Say!" style="width:150px; " disabled />
<script>
	update()
</script>
[/code]
--chat.php----------------------------------------------------------------------------------
[code]
<pre>
<?php
if(isset($_GET['text']))
{
	$already = file("text.txt");
	$already[] = htmlentities($_GET['name'])." says:\t".htmlentities($_GET['text'])."\n";
	$handle = fopen("text.txt",'w');
	$iwant = array_chunk(array_reverse($already), 20);
	if(!fwrite($handle, implode("", array_reverse($iwant[0]))))
	{
		die("grote error!");
	}
	fclose($handle);
	echo implode("", array_reverse($iwant[0]));
}
else
{
	echo implode("", file("text.txt"));
}
?>
</pre>
[/code]
--text.txt------------------------------------------------------------------------------------
[code]
Hij doet het verdorie!
[/code]