PDA

View Full Version : Help with ASP chat script


ortora
06-14-2005, 10:30 PM
Hello there,
we have purchased a chat script called ShoutBox (http://www.xigla.com/shoutbox/index.htm) and are in need of one edit. Basically if you look at the chat off that link (on the right hand side), you can see that people enter their name (login) and then start chatting. The login page simply creates a cookies with the name and then checks it using this coding:


<%
'/// Get Nick Name
nick=request("nick")
xlaSBnick=request.cookies("xlaSBnick")

if nick<>"" then
response.cookies("xlaSBnick")=nick
xlaSBnick=nick
end if
if xlaSBnick="" then
formproperties="action=bottomframe.asp onsubmit='return validatenick();'"
else
formproperties="action=receiveframe.asp target=xlaSBreceive onsubmit='return shout();'"
end if
%>


What we need is to be able to add a list of currently logged on users (ideally on a separate frame), because the way it is, you never know if anyone is online and you might end up talking to yourself...

if anyone can help please let me know and we are willing to pay if this doesn't cost too much anyway. Should be simple to just read off the cookie and write the name of each users on the page.

thank you for your time
cheers
o.

Morgoth
06-14-2005, 11:51 PM
What you must do is keep track of each user that is logged in, or has visted the shoutbox.
Store their user name in a database a long with the time and date.
The time and date will be used for timeouts.

When the user leaves, the date and time field next to it's name will not refresh, and therefore it will be an older date.

Everytime a new user logs in or vists the shout box you will run a script that will check the time of all users logged in, and if the time is older than 5 minutes (or what ever you want the timeout to be) the user name will be removed from the database.
When that name is remove, it will not show up in the "Online Users" section of the website.

Do you understand what I am saying?

This is the same method I used for the member timeout script.
http://www.codingforums.com/showthread.php?t=10766

If you do not understand, please reply. :cool:

Edit:
I would also like to add, that I have made my own script of a shoutbox, and it wasn't very hard. There are some features missing compaired to the one you have, but I can pretty much add anything, if I wanted it.
http://www.morgoth.sonnexh.com/
^- This one is written in PHP, but it was just manually converted from my ASP version.

ortora
06-15-2005, 12:04 AM
hi there,
thanks a lot for your time :) If I understand right with the way you suggest, I should already make a list of users and have them in a database. My problem is that the chat is free to use at anytime, so people come and go and put down random names, rather than having to register a name.. otherwise it would be so hard for me to guess all names eheh

any way of having a frame that just reads who is on at the moment and display a list of names?? all i would need is a simple list, plain text.. not sure how to get the cookie name from each user logged on at any time..

anyway thanks a lot for your help!!

Morgoth
06-15-2005, 12:18 AM
ortora, you can't just grab the user name, they have to provide it to you because it's in a cookie.

So when refresh the shoutbox page, or in your frame (I assume you mean an iframe) you will check for the cookie, and if it exists, it will add the username as well as the current date and time to a database, or if that username is already in there, you update the date and time!
This same script also checks the database to time people out and delete the username from the database.

Then to list people, you read all user names that are in that database.

If you start the script, I will definatly help you with any coding problems.
What kind of database is the shoutbox using? MySQL? Access?

ortora
06-15-2005, 12:22 AM
hi morgoth,
the script doesn't use any databases. It's plain ASP and cookies. That's why this sounds hard to me, I have no experience at all with these things except for simple coding, so having to setup a database sounds impossible!
Even reading the cookie and writing a list is hard for me :(

Morgoth
06-15-2005, 12:26 AM
Where are all the shout messages stored?
Do you have an IM program? MSN, ICQ?
We can chat over that, and I can help you figure out what you need.

Morgoth
06-15-2005, 12:44 AM
Can you use MySQL or Access on your host?
It doesn't really matter where the shout messages go, but if they already a database, we can just use a table inside of the db.
You just need to give me some information so I can get a general feel for how the code will work.

Morgoth
06-15-2005, 03:21 AM
I wasn't going to write this code for you, but here it is...
Reply for help reading to code.


<%Option Explicit%>
<%
Dim oConn, StrConn, SQL, oRS, strCookieName

strCookieName = "Teddy"

Set oConn = Server.CreateObject("ADODB.Connection")
StrConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("onlineusers.mdb") & ";"
oConn.Open StrConn

SQL = "SELECT ID FROM tblOnline WHERE fldUsername = '" & strCookieName & "'"
Set oRS = oConn.Execute(SQL)

If oRS.EOF Then
SQL = "INSERT INTO tblOnline (fldUsername, fldDateTime) VALUES ('" & strCookieName & "', Now())"
oConn.Execute(SQL)
Else
SQL = "UPDATE tblOnline SET fldDateTime = Now() WHERE fldUsername = '" & strCookieName & "'"
oConn.Execute(SQL)
End If

SQL = "SELECT ID, fldUsername, fldDateTime FROM tblOnline ORDER BY ID DESC"
Set oRS = oConn.Execute(SQL)

Do Until oRS.EOF
If DateDiff("n", oRS("fldDateTime"), Now()) => 5 Then
SQL = "DELETE FROM tblOnline WHERE ID = " & oRS("ID")
oConn.Execute(SQL)
Else
Response.Write oRS("fldUsername") & ", "
End If
oRS.MoveNext
Loop
%>


This code uses an access database. Maybe you might use a different one for your shout box. You still haven't told me what it uses.

Also, I just added a fake name for the cookie name string (strCookieName) so you'll have to use the correct code to grab that name out of the cookie.

Here is the access database I used: