Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2004
    Location
    Leamington, UK
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Unix timestamp question

    Hi guys,

    ok here is my dilema.

    When a user logs in it updates the db and changes the time field and inserts the current time ( unix time stamp )
    then every page they visit it updates the time

    if that user closes the browser without logging out they are still shown as online because they havent cleared the sessions and updated the db.

    what i want to know is .. is there a way i can determine whether a user is still online by checking the time in the db with the current time and if no activity for 30 mins then set them to offline.

    im new to using the unix time stamp

    any help would be grately appreciated

    regards,

    Chris

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not quite sure how your question is related to the UNIX timestamp, but anyway... provided you use MySQL for your database, you can set all users who haven't shown any activity in the last 30 minutes to offline:

    Code:
    UPDATE mates 
    SET status = 'offline'  
    WHERE timeField < date_sub(now(), interval 30 MINUTE);
    Of course you have to adapt this query to your table structure. And this assumes your field that stores the timestamp is a date type, so you can perform date manipulations on it.
    You have to run this query before checking who's online, which you can do afterwards.

    EDIT: Small typo: It should be "date", not "data" type.
    Last edited by mordred; 07-08-2004 at 10:47 AM.
    De gustibus non est disputandum.

  • #3
    New Coder
    Join Date
    Jul 2004
    Location
    Leamington, UK
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,


    will try that out soon


    thanks for the help mord

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    MySQL has unix timestamp functions as well so you could probably do something like..

    Code:
    SELECT blah 
    FROM table 
    WHERE timefield > (UNIX_TIMESTAMP(NOW()) - (30*60))
    though I have not tested the above , also not sure if you actually need the NOW() , I suspect not.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •