Home » Tutorials Beginner Tutorial

Simple AJAX Chat

2.7/5.0 (17 votes total)
Rate:


March 20, 2006


This Ajax Chat is so simple, you will laugh!

 


try it out

if spammed or crowded, try room2 or room3


Basics

  • we have 2 files - index.html and w.php
  • index.html reads the content and sends your message to w.php
  • w.php writes the content and prunes it to $maxlines lines
  • content stored as text in chat.txt
  • this uses 2 http_requests - 1 for checking the content, 1 for sending your message


The setup is as simple as it can be

2 steps

  • copy index.html and w.php in a directory of your choice
  • create a file called chat.txt with write-rights for php

you could also do like this:

  • copy index.html and w.php
  • chmod 777 the whole dir
  • start the app to create the chat.txt file
  • chmod 755 the dir and 777 the chat.txt


Ridiculously Simple - The Source

Feel free to use/modify it for whatever you want. It's just about the idea.


The 20 lines of JavaScript sourcecode you find in here:

And this is the w.php, which also prunes the content:


add this on top to get a minimum-wait time:

  	$waitsecs = 5;
 	$lastvisit = $_COOKIE["lachatlv"];
	setcookie("lachatlv", time());

	if ($lastvisit != "") {
		$diff = time() - $lastvisit;
		if ($diff < $waitsecs) { die();	}
	}

 

 

 

 

This article was written by Chris at Linuxuser.at .


Add commentAdd comment (Comments: 0)  

Advertisement

Partners

Related Resources

Other Resources

arrow