PHPBuilder - PHP-Based Chat Room Page 6

RSS Twitter

PHP-Based Chat Room - Page 6

by: Mike Hall
July 30, 2000

Finally we need a way to get the troublemaker's IP in the first place. I do this by logging $name and $REMOTE_ADDR in a file called iplist.html. At a separate, secret URL I can view the message and monitor the IP addresses at the same time. This has the added bonus of being able to spot impersonators - a common crime in these places.
iplist.html is created in much the same way as messages.html. First we extract the current values from iplist.html, we strip out the header, footer and oldest IP record and then create a new record, new header and new footer. To make the layout more clear, I used a table.


"<html><body bgcolor=\"#000000\" text=\"#ffffff\"><table border=\"0\">\n";
$footer "</table></body></html>";
$new_ip "<tr><td>$name</td><td>$REMOTE_ADDR</td></tr>\n";

$ip_array file("iplist.html");
for (
$counter 1$counter 20$counter++) 
$old_ips.= $ip_array[$counter];

Simply write that to the disk the same way as we did the message file and there we have it. A simple web-based chat room. Better cross platform compatibility than Java and no need for anything more than a web browser - I'm told that even the Dreamcast works with this!
Somethings you might want to try yourself include combining common pieces of code into functions, writing a script that will automatically add troublemakers to the banned list and writing a regex expression that scans a message text for URL's and e-mail addresses and automatically turning them into likes (as Outlook Express and ICQ do).
Play around, have fun, experiment. I did. This is how I started in PHP and now I've made a career of it. Happy Chatting.

« Previous Page

Comment and Contribute

Your comment has been submitted and is pending approval.

Mike Hall



(Maximum characters: 1200). You have characters left.