SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm going to set up a 'currently browsing' type thing, probably just using the numerical number. But I might expand it to show the names if they are logged in.

    I have a couple of questions. Firstly, I'd like to put the current time into a mysql table in a format so I can say take all the names inserted into the database in the last 5 minutes say. I know about the 'date' type. Is there a similar 'time' (with date) type. I'm almost sure there is actually, I'd just like to know what it's called, and how you insert the time (I'm u sing CURDATE() to insert the date).

    My second question reguards how VBulletin does it's "logged" users. I have noticed it seems very accurate. Almost like it's checking the actual value of a users cookie but... other peoples values. If I go to the main page of sitepoint, it feels like it's checking everyone elses cookies, which seems a bit strange. I'd just like to know how that's done, because the way I plan to do it with the 'users browsing in the last five minutes' doesn't seem like the best way.

    Anyway, thoughts and help most appreciated.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You want to use a DATETIME type or a TIMESTAMP type. The TIMESTAMP type is a series of numbers with no separators and has a smaller range of values, though using the DATE_FORMAT() function you can make the output look like anything.

    As for your other question: they most likely store logged in users in a database, and when you access a certain page, it queries the database for the logged in users.

    Oh, and curtime() will give you the time, but since you want both the date and the time use now().
    Last edited by 7stud; May 4, 2001 at 17:49.

  3. #3
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that's the way I would do it, but that system would work on a users logged in the last 'minute' or whatever, if somebody was reading a long article it might say they were logged out when they weren't. I feel VBulletin actually queries the users in some way when they get their lists. But Maybe I'm wrong. I know Ikonboard works on that 'last 15 minutes' system.

    With timestamp, how do I insert the time? what is the format, is there a function to do it like CURDATE() ?

    Thanks for your help by the way

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    For details go here:

    http://www.mysql.com/doc/manual.php?...y=date&depth=0

    and see the lines I added to the bottom of my last post.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Why would a system that stores logged in users in a database show a user as logged out when they are reading a long article?

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again..lol,

    You can very easily do database queries that return only users that logged in during the last 15 minutes by comparing their field logged_in_time to NOW() in a table of logged in users.

    By the way, you can't read a users's cookie while they are just sitting at one of your site's pages. They have to move to another page so that one of your scripts is called, then you can check for a cookie and record a time if you choose.
    Last edited by 7stud; May 4, 2001 at 18:09.

  7. #7
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, heh, I missed you giving me the info on the timestamp... for some reason. I must be drunk.

    Here's the thing. With a database system you would probably insert an id the current time and the users ip when they enter, ONLY IF there is no ip in the database of that number already IN the last 15 minutes.

    Anyway, you would then query the database select from the table where the time is less than 15 minutes less than the current time. blah blah. The thing is this could be updated whenever a user went to a new page (if the ip was there, just update the time rather than entering a new row) however it wouldn't be dynamic on the other side. If *I* go to the site and it selects the rows from the last 15 minutes, who's to say a user just hasn't refreshed his login by visiting a new page in 15 minutes, he might still be on the site.

    The only way I can see to counter this would be to actually check their system to see if their on, I'm wondering if that could be done with cookies?

    This would be an even bigger problem if you were trying to do a more 'realtime' login feature, say the last minute rather than 15.

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again,

    Ok, the more I think about this the more I am certain of what is happening with logged in users, so I am going to go out on a limb here and say this:

    If you want to have an accurate reflection of what users logged in the last 1 min, 5 minutes, or whatever, you have to use a database to store the logged in users.

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Nope you aren't drunk, I most likely edited my post while you were reading it.

    I am still totally confused by what you are saying, though that may be because I don't understand all the issues involved. If I were trying to do the "logged in users" feature, I would record the username when the person logged in and the timestamp. Then I would query the database based on my time threshhold which could be 15 secs or 15 minutes. That would give me all the users I wanted. It does not matter if they went to another page on the site, or if they logged out.

  10. #10
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Ah, hah! Now, I see some of the issues you are talking about. When you want to create a "users currently online" type of thing, you need to know when someone logs out. To handle that, you need to use sessions. When a user logs out the session is terminated, so you would update your database to delete sessions that had expired. That udating would occur when users still on line went to a new page that displays the users currently on line. The new page would check all the entries in the table to see if the sessions still existed and if they didn't the entry would be deleted or skipped over.

    Hmmm...that makes me wonder if a session would end if I don't close my browser, but I continue on to another site. I think the session only ends when the user closes the browser, so a person could visit your site and continue on to another site, and it still shows them online. I guess my response to that would be so what, they are still online, and if they use the back button, they can get back to your pages.
    Last edited by 7stud; May 4, 2001 at 18:42.

  11. #11
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually a session ends after session.gc_maxlifetime sessions, which is set to 1440 (24 minutes) by default in your php.ini. There is no way for a php script to somehow know that you closed your window or went to another site. The way a "logged in users" script works is that every time a page is loaded the lastLoggedIn column in a database is updated with the current time. The "logged in users" part then queries the database for all users where lastLoggedIn is greater than time() - 15*60 or so. So, if you're reading a long article and don't end up clicking a link for 30 minutes, you'll be seen as logged out for the last 15 minutes.

  12. #12
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it seems that's the only way to do it, and the way I innitially planned to do it. I always though VBulletin's system was really dynamic, I'm not sure why. But I guess this is the only way. Thanks people

  13. #13
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Anarchos,

    It is my understanding that a session ends either when a user closes the browser OR when session.gc_maxlifetime is reached. Are you saying a user can shut their browser, leave the computer, and a second user can sit down and open up a browser and access the session?

    If I am right, and I think I am, then this statement is wrong:
    There is no way for a php script to somehow know that you closed your window
    because you can check to see if a session still exists for that user when another user accesses a page that displays "currently logged on users".
    Last edited by 7stud; May 5, 2001 at 18:25.

  14. #14
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, how do you think the php script checks to see if the user has closed his browser? You can't.

  15. #15
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Take a look at phpUseronline from http://www.netone.at

    Sean


Bookmarks

Posting Permissions

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