Session counting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pradeep

    #1

    Session counting


    Hello all,

    There is system. Users are logging , working and logout.
    Suppose, 5 users are working and Admin wants to find out no. of users
    working on system with their name ?

    How to find this ?

    Thanks in advance.
  • Toby A Inkster

    #2
    Re: Session counting

    pradeep wrote:
    There is system. Users are logging , working and logout. Suppose, 5
    users are working and Admin wants to find out no. of users working on
    system with their name ?
    Depends. Are you on a shared server? Are you using PHP's standard sessions?

    If yes to both, then the answer is no! (Well, it could be done, but not
    reliably.)

    Best option is to write your own session handler -- i.e. the piece of code
    which deals with saving and restoring session data -- easier than it
    sounds! Store the session data in a database, and then you can simply use
    a SQL COUNT(*) query to find the number of open sessions.

    See: http://uk2.php.net/manual/en/functio...ve-handler.php

    The comment from maria at junkies dot jp, dated 09/12/07 is a reasonably
    good starting point.

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 10 days, 21:16.]

    Sharing Music with Apple iTunes

    Comment

    • Jerry Stuckle

      #3
      Re: Session counting

      pradeep wrote:
      Hello all,
      >
      There is system. Users are logging , working and logout.
      Suppose, 5 users are working and Admin wants to find out no. of users
      working on system with their name ?
      >
      How to find this ?
      >
      Thanks in advance.
      >
      In addition to what Toby said, you can do it even on a shared host, but
      neither is reliable. They work fine if the user logs off, but not if he
      just shuts down his browser.

      To do it without your own session handler, you need to keep a list of
      logged-in people. Probably a flag in the database would be most
      appropriate.

      But you'll also need a timestamp field to tell when they did log in, and
      if they've been logged in longer than the session time limit, you need
      to clear the flag. Maybe easier would be just a timestamp - if it
      exists, the person is logged in. When the person logs out, clear the
      timestamp.

      Then you need a program (i.e. a cron job) to go through the list on a
      regular basis to clear users who have been logged in to long.

      But none of this is very accurate. They really only tell you who logged
      on - not whether they were still active.


      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      Working...