|
||||
| Register--Login--Top 20 Posters--Search Topics |
Forum Main>>Tutorials>>Simple chatbox tutorial | ||
Chipmunk![]() Rank:Settler of Bobland Group: Head Administrator Posts: 2867 IP Logged PM ID and RPS ID: 1 PM [Chipmunk] View Member Photo | Last replied to on Sat Mar 06, 2010 01:31:23 Edit Post|Quote Ok, this is going to be a tutorial that will show you how to build the frontend of a PHP/MYSQL based chatbox that has a WYSIWYG built in. First we need to set up the mySQL database: We're going to call this table chatmessages for this tutorial. It needs 5 fields: ID - Bigint, primary , auto increment name - varchar 255 IP - varchar 255 postime - bigint message - I'd say tinytext, but you can do medium text if you want your users to be able to post over 400 chars per post. The second table is for a list of all ipbans: IPID - Auto generated IP, primary Auto increment, bigint IP - varchar 255 - this is where we wil store the actual IP So you need 3 files for the main chatbox. 1 file we'll call chatbox.php as the main file to hold the other two frames. Another file called chatlog.php that will Display the messages and a third file called send.php we'll use to send the messages. The later 2 files will be iframes in the first file. We also need a connect.php file for mySQL database connection: connect.php
First we will work on submit.php
This is the file that will submit a user's message into th database. At the bottom you see the form that asks for your poster's name and the message he wants to post. The onclick and following javascript function allows for clickable smilies. If you want more, simple add more smilies in and copy and paste more:
lines in, change the :( into the character you want for your smiley and the image path to the image path of your smiley. The code that comes in the:
case is basically validation code for message, it checks to make sure the poster's name and message is at least 1 character long and if it isn't, it doesn't post and gives an error message telling them that one of the required fields is not valid. Next it gets the poster's posting IP with the $_SERVER["REMOTE_ADDR"] function and checks that IP against the table of banned IP with $checkforbanned. If the IP is found in the list of banned IPS, it throws an error message saying that your IP is banned and does not post the message. Finally, if all the conditions are met, it grabs the current unix timestamp wth $date("U") and posts all the information into the message database. Now lets look at chatlog.php, the file that displays the messages, the newest messages will be posted at the bottom:
Basically , this first counts the number of messages there are in the database first, then subtracts 20 from that number and stored that value in $startrow. Then we grab all the messages from $startrow to the last message in the database and look through the array to display the 20 messages, with the latest message at the bottom. The smilies function replaces the smiley characters with the actual smiley images, not that this can also be used as a bad words filter. The last line simply refreshes the page automatically every 2 seconds, so that new messags will automatically come up, just like a real chatroom. Now we can look at chatframe.php which is a simple page with two iframes to hold the submit page and the chatlog page. chatframe.php
There's really nothing to this file, just two iframes to hold the other two files. The next post will be the admin files. ----------------------------- Chipmunk, Supreme Administrator | ||||||
Chipmunk![]() Rank:Settler of Bobland Group: Head Administrator Posts: 2867 IP Logged PM ID and RPS ID: 1 [PM Chipmunk] View Member Photo | Posted at Sun Mar 18, 2007 16:12:55 Edit post|Quote The next part of this tutorial will be building some basic admin things for the chatroom. All these files will go in a /admin folder which will be password protected. I am assuming you have a control panel(such as cpanel or directadmin) that offer password protection for directories. If you don't please take a look at http://www.javascriptkit.com/howto/htaccess3.shtml Basically, this simple admin panel will consist of three primary functions, banning IPs, editing messages, and deleting messages. So put this link bar at the top of very page of this admin panel:
First we will look at banip.php, its quite simple:
Basically this is just a form and when you hit submit it checks to see if anything was entered, and if something was, it inserts it into the banned IPS database. Now lets look at unbanip.php:
This basically prints a form, queries the database to get all the banned ips and uses the while loops on the query results to print them all out as options in a select element of the form. When you hit submit, it deletes the IP from the banned IP list based on the ID of the IP stored in the database. Now lets look at the code for editing and deleting messages: editdelete.php
This print out a simple form asking you for a search term that appears in the message you are searching for. Since we are matching on like, if you leave it blank, all messages will be returned in last-to-first order. After you hit submit, it queries for the message containing the terms you search for and print them neately in a table so you can edit or delete. Now we require 2 more files to finish this admin panel, editm.php and delete.php, lets take a look at those. editm.php
So Basically in this file, when you click on the edit link, it draws out the contents of the page based on the ID defined in the URL. Then it prints a form with the message in the textfield you can edit. When you click submit it passed the ID of the message and the edited message and then uses a mysql update query to update the message. So at last lets look at delete.php
This code get the ID from the ID specified in the URL, stores it in a hidden field and confirms that you want to delete the message. Once you hit the delete button, it passed the ID and then deletes the message from the mySQL database based on that ID. Thats it, a simple chatbox with admin panel. ----------------------------- Chipmunk, Supreme Administrator | ||||||
| busterkeaton Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 13365 [PM busterkeaton] RPS score: 0 RPS challenge | Posted at Sun Aug 12, 2007 19:29:57 Edit post|Quote it always says could not connect... is there any problem?? ![]() | ||||||
| infinity Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 13496 [PM infinity] RPS score: 0 RPS challenge | Posted at Wed Aug 29, 2007 03:21:07 Edit post|Quote where is the file for chatbox.php?do you have the compete files for download? | ||||||
| Tomo Rank:acorn Group: members Posts: 18 IP Logged PM ID and RPS ID: 15238 [PM Tomo] RPS score: 0 RPS challenge | Posted at Mon Feb 25, 2008 17:23:28 Edit post|Quote Awesome I got the mod working for my wee game
Tomo | ||||||
| Tomo Rank:acorn Group: members Posts: 18 IP Logged PM ID and RPS ID: 15238 [PM Tomo] RPS score: 0 RPS challenge | Posted at Mon Feb 25, 2008 18:24:00 Edit post|Quote Awesome I got the mod working for my wee game
Tomo | ||||||
| j0nath0n3 Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 16602 [PM j0nath0n3] RPS score: 0 RPS challenge | Posted at Fri Jul 04, 2008 19:31:36 Edit post|Quote i did what you said but now how do i view this on my website? it has not changed anything.. :X ----------------------------- Yo. | ||||||
| computerwiz Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 22024 [PM computerwiz] RPS score: 0 RPS challenge | Posted at Wed Apr 22, 2009 07:42:48 Edit post|Quote Hi,Could you copy and paste the mysql database on how i would enter it in MyPHPAdmin.It says syntax error if i copy and paste it as you put it in your first post.I dont know how i enter the mysql in the database so if you would that be great or create a text file and upload please.Also do i need your permission to edit this script in anyway or to make it into a extension for a program i use? or can i just use it as i wish without any license etc?Thankscomputerwiz | ||||||
| Trex2303 Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 24027 [PM Trex2303] RPS score: 0 RPS challenge | Posted at Tue Aug 11, 2009 03:25:58 Edit post|Quote Well I got it all set up, with the exception when I put in any messages, it all comes up as 0 instead of the actual message...Any reason why it would do that ? | ||||||
| tomhick Rank:acorn Group: members Posts: 2 IP Logged PM ID and RPS ID: 24636 [PM tomhick] RPS score: 0 RPS challenge | Posted at Mon Oct 05, 2009 00:57:33 Edit post|Quote Online chat is a way of communicating by sending text messages to people in the same chat-room in real-time. Some chat rooms such as Yahoo! use both text and voice simultaneously. The oldest form of true chat rooms are the text-based variety. Talkomatic, developed on the PLATO System around 1974, has a strong claim to have been the prototype of the text-only chat room. A notable 1980's text-based chat system was Freelancing' Round table. The most popular of this kind is Internet Relay Chat (IRC) where each "room" is called a channel. The popularity of these kinds of chat rooms has waned over the years, and IRC's popularity has rapidly given way to instant messaging. Also a notable number of people were introduced to chat rooms from AOL and web chat sites.There are also graphical user interface (GUI) text-based chat rooms which allow users to select an identifying icon and modify the look of their chat environment. ----------------------------- generic cialis - new dvd releases this month - mens watches | ||||||
| nasim Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 26296 [PM nasim] | Posted at Wed Jan 06, 2010 07:24:01 Edit post|Quote A simple chatbox written in PHP and MYSQL database, includes table setup and basic administration area. Simple chat box in PHP or MySQL tutorial. The next part of this tutorial will be building some basic admin things for the chat room. That's it, simple chat box with admin panel. Free download simple chat box HTML code Files at Software Informer Free Colored scroll Bars is powerful tool that creates Java Script code and CSS Style. I was wondering if there is some standard code out there which would allow me to have a simple chat box on my WWW site so that anyone viewing my website and basically its a simple chat box like others out there except this one is a lot easier to use than most. It has an installation script and is really easy Thank you for sharing this useful information with us. Nice, you have done a very good job. ----------------------------- Spiele kaufen | ||||||
| cerse Rank:acorn Group: members Posts: 5 IP Logged PM ID and RPS ID: 27372 [PM cerse] RPS score: 0 RPS challenge | Posted at Thu Feb 25, 2010 00:17:59 Edit post|Quote Affiliate is system is what in which you track your current member referred some new member to join your site or bicsi training purchase your product. You give some reward for it. Making or better say coding your affiliate system is easy. Benefit of own script is you can customize it as per your need. | ||||||
| phphunger Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 27669 [PM phphunger] RPS score: 0 RPS challenge | Posted at Sat Mar 06, 2010 01:31:23 Edit post|Quote Hi, I have followed all the stuff whatever you posted in this tutorial. Eventhough i didnt made any mistake it shows the following error:Unknown column 'postime' in 'order clause'Could you please tell me why the error is coming...And if possible try to tell how to develop the chat system for a gameing website where the games can chat online with the chat box...Eagerly awaiting for your response.. ----------------------------- PHP Programmer | ||||||
Page: 1 |