Jump to content

Truncating


thisisedie

Recommended Posts

Hello. First I'd like to say that I know my way around pretty good but I am not a veteran PHP programmer so talk to me like I'm stupid please  :D

 

Ok... I have a simple chat script set up that will only be used by a few people. I figured out how to truncate the chat when someone logs out, but I can't figure out how to truncate only if ALL users log out. Can someone lead me in the right direction?

 

Thanks  :-*

Link to comment
Share on other sites

Depending on how you store user activity this should be relatively simple.

 

For a chat script a user can "logout" or "timeout", a timeout is when the user has no activity for say 5 minutes.

Everytime a user sends a message or refreshes the page or basically interacts with the chat script there should be a timestamp in that users field, or a new entry with the userid and timestamp in a table like "active_users". Lets go with the active users method;

 

User interacts with the site -> Timestamp inserted or updated in the active_users table.

Whenever the script refreshes or someone requests content, it should check the "active_users" table for any timestamps that are more than 5minutes old. This is very simple as its just; if $mysql_user_timestamp + (60*5) < time() then delete the entry from the active users table.

Similarly if the user manually logs out the active_users entry is removed for that user.

 

That way you know if there are no entries in the active_users table then there is no one online and therefor you can truncate the chat.

 

Is this what you are trying to do?

Link to comment
Share on other sites

Do you even list the users that are in the chat?

 

If not, i would suggest doing so by creating a seperate flat-file used to store usernames with a timestamp of their last activity on each line.

Something like:

someuser141::1296501723

 

This would be relatively easy to go through and put the users into an array which you can echo out. And also check their activity at the same time (for timeouts).

 

To get a timestamp in php use the time() function.

 

Once you get this working then you should work on truncating since you can then nkow how many people are in the chat. You could even save the chat to a log file once all the users have left.

 

hope this helps

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.