Results 1 to 7 of 7

Thread: Session Variables

  1. #1
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Session Variables

    Hey DD,
    Quick question: is there any way to count active sessions? What i mean by that is, like you see on forums, Users online: 250. How does it get that 250? I'm assuming it counts the current sessions or something similar. Is that how one would go about that? Or should i put a table in my database that updates each time someone logs in or logs out?

    Thanks.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It increments it when the user logs on, then stores the time the user was last seen. Each time a page is accessed, it goes through the database and marks each user as logged out if they haven't been seen for the last, say, five minutes, and decrements the counter.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah, OK.

    How would one go about scripting that?

    Thanks.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Or should i put a table in my database that updates each time someone logs in or logs out?
    Yep


    As for scripting... the logic isn't that hard... you've got the right idea. Now just get an idea of how php works, along with mysql, and there ya go. Here's a good tutorial site: http://php-mysql-tutorial.com/
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?php
    mysql_connect("localhost", "username", "password");
    mysql_select_db("database");
    mysql_query("update userstable set lastseen=NOW() where id=$userid;");
    mysql_query("update userstable set logged=0 where logged=1 and DATE_SUB(NOW(), IN
    TERVAL 5 MINUTE) > lastseen;");
    $rs = mysql_query("select * from userstable where logged=1;");
    $numusers = mysql_num_rows($rs);
    ?>
    Predefined variables: $userid -- ID of user in database
    Structure of userstable:
    Code:
    +----------+------------+
    | Field    | Type       |
    +----------+------------+
    | id       | int(11)    |
    | lastseen | datetime   |
    | logged   | tinyint(1) |
    +----------+------------+
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Holy cow. That's way above my level of PHP.

    I'll work with it, see what I can do.

    Thanks, Twey.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's more SQL than PHP.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •