Over at the .NET Butchering (and JAVA messes) blog they have posted a very good tutorial on creating a Chat application in PHP using Ajax. In Web 2.0 social applications chat is very often a desired feature.
Below is an excerpt from the tutorial.
The first thing to be done is creating MySQL tables:
CREATE TABLE `db_name`.`chat_rooms` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(45) NOT NULL,
`description` text NOT NULL,
`table_name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `db_name`.`roomX` (
`id` int(10) unsigned NOT NULL auto_increment,
`date` datetime NOT NULL,
`message` text NOT NULL,
`user` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The first table, chat_rooms, contains a list of all available chat rooms, used to know wich table name will be used for each room. The second one, roomX is a template for a "chat room-like" table: it contains the date (date+time) of each message, the message itself and the user that inputed it (actually it should be an integer, that refers to an appropriate users table, but this is simple version of the script without logging features).
The first thing we are gonna do is execute those SQL scripts (we will be using MySQL and PHP native methods) replacing "roomX" with i.e. "friends_table", and after that we are going to populate the first table, to add an available chat room:
INSERT INTO chat_rooms(name,description,table_name)
VALUES("Friends chat","Comment...","friends_table");
The next step is to compose the "web application". Let is see this picture:

We will use a main page, chat.php, a dinamically reloaded page, room.php and a simple iframe with inside the page sender.php with some controls to post a message.
Let is see chat.php, removing all HTML stuff (like header and formatting, that is up to you):
<?php
session_start();
/* probabily login stuff */
$_SESSION[chat_time] = $date;
?>
<script type="text/javascript" src="timer.js"></script>
<script type="text/javascript" src="httpRequest.js"></script>
<script language="javascript">
var chatRoomId=<?=$charRoomChoosen?>;
</script>
<body onload="InitializeTimer(); StartTheTimer();">
<div id="chatText" style="overflow:auto;"></div>
<iframe src="sender.php" name="msgFrame"></iframe>
</body>
read more: ajaxonomy
Related Stuff
-
MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.
-
Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone
-
TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support
-
ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.
-
Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.
-
Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software
- PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.
Be the first ... |Add your comment.
Your Comment ...
Name (required)
Email (required, hidden)
Website
