'Comments' - a shoutbox by Bryan - May 2005 - firstname.lastname@example.org This little project came to be when I couldn't find a shoutbox that was quite to my liking. I'm no expert with PHP, and the coding is far from elegant, but it seems to work well enough as a shoutbox/guestbook/chat script. I know it could be improved upon. After a couple of people asked if they could borrow the script, I kinda packaged it up as you see it now (mainly, I just moved some user variables to an include file for portability) Features--------------------------------- -Functions as a guestbook/shoutbox, but also as a quasi-chat room by virtue of a 20 (adjustable) second silent refresh - no annoyong IE 'tick' - (it really isn't very efficient as a chat room, but I've used it that way on my webcam site) -Displays the national flag of the visitor (courtesy of an IP lookup at www.hostip.info) -Tooltip display of IP, date, time of post on mouse over a comment (to reduce clutter) -Site owners comments receive a distinguishing highlight, and the site owners name cannot be used by others - see comments.inc.php for explanation Requirements: A web server running php and mysql. The script is intended to run within an iframe. Basic knowledge of setting up a db table and connecting to mySQL. Knowledge of phpMyAdmin or similar for deleting posts, there is no admin panel for this script. Component files-------------------------- commentframe.html - a simple frameset containing commentform.php and commentlist.php. I originally set out to have this work with PHP_SELF, but, well, long story...it probably could but I'm lazy. commentform.php - the form where users will enter their name and comment. No editing is required. commentadd.php - the logic that inserts the contents of commentform.php commentlist.php - the comment listing comments.inc.php - set database and site specific variables here commments.sql - the table schema for your database, uses a single table named comments. If that conflicts with your database setup, well, you'll have to modify the values hard coded in commentadd.php and commentlist.php. The database name can be set to whatever you want (see below) Installation----------------------------- If you're reading this, you've unzipped the files. That's a good start. Modify the file comments.inc.php for your site: //Usually you can leave 'localhost', change username and password for your SQL //server (ask your webhost if you don't know) $dbcnx = @mysql_connect('localhost', 'username', 'password'); //$admin_name and $display_name are related, heres the concept - You are Bob and //the site owner. You don't want anyone else to use the name 'Bob', and you want //your comments to have owner highlighting. When you make a post, use the //admin_name, it's like a password, keep it private. It will display as the //display_name, be in red, and not have the country flag displayed $admin_name = "Bob_xyz"; $display_name = "Bob"; //Change comments to the name of an available database $dbname = "comments"; Upload the files to your webserver, keeping them in their own folder would be a good idea, call it 'comments'. If you use phpMyAdmin, you can run comments.sql to set up the needed table, or do it manually if you want (it is assumed you already have an available database): CREATE TABLE `comments` ( `id` int(10) NOT NULL auto_increment, `date` datetime NOT NULL default '0000-00-00 00:00:00', `name` varchar(255) default NULL, `comment` varchar(255) default NULL, `email` varchar(255) default NULL, `ip` varchar(16) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM; All that remains is to create a web page with an iframe to contain commentframe.html (you could run it outside of an iframe I guess but it seems to fit better inside one): <iframe src="commentframe.html" width=482 height=140 vspace=3></iframe> You can modify this to your liking. If you want to change the refresh rate, you have to edit commentlist.php, it's near the top and 2 values have to change (they are currently set to 20 seconds). Keep in mind however that every refresh accesses you sql database - if you have a busy site this might freak out your webhost. Another consequence of this is that newly added comments don't appear until the the next refresh, that's why this isn't the perfect chat room. Also in commentlist.php, on line 166, the number of comments retreived is limited to 50 - you can change this to whatever you like, again, at the risk of complaints from your webhost. It's impossible to provide a 'good' number. The CSS is pretty messy, still getting hang of it. That's about it. I have very little time for support with this, so you're kind of on your own if it doesn't work out.