SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Aug 2003
    Location
    KL
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question One User Can Login Once Only?

    I need a page that only allows any user to login once. Any subsequent login with the same username will be deny.

    I am planning to do it this way,

    1) Update user login flag in MySql database when user login or logout.
    2) Run a cron job to check the login flag every 10 seconds to logout non-active user (user that has leave the page) or user that didn't logout properly due to system crashed and etc.

    How do i check when a user leave the page?
    Also i would like to know if there are other better way to implement something like this?

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    basically yes, log user activity to a table and cleanup that table periodically , 10 seconds seems a bit extreeme though, I would run garbage collection whenever someone logs in?

  3. #3
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by edwardkoo
    I am planning to do it this way, ...
    It is a bit untidy to have the login recorded in two places. Have a look at PHP's session handling functions. It is pretty easy to create a database version of the session handlers. A login can then trigger some DB checks (a previous unexpired login for example) and react appropriately. Our current system has these rules for logins...

    1) Logging in twice with different cookies within 10 minutes: Probably a robot, so new login rejected.
    2) Logging in twice after 10 minutes of inactivity: Probably just changing desk at the office. The new login supercedes the old.
    3) Working after 60 minutes of inactivity: Gone off to lunch, so log them out.

    All of this, plus the cookies, are handled within the SessionPool class.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  4. #4
    SitePoint Guru dagfinn's Avatar
    Join Date
    Jan 2004
    Location
    Oslo, Norway
    Posts
    894
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by edwardkoo
    How do i check when a user leave the page?
    This is an interesting question which is somewhat independent of the rest of the discussion. I believe the only way to do that is to use a JavaScript onUnload. But I've never seen anyone implement anything workable based on that. Has anyone done it?
    Dagfinn Reiersøl
    PHP in Action / Blog / Twitter
    "Making the impossible possible, the possible easy,
    and the easy elegant"
    -- Moshe Feldenkrais

  5. #5
    SitePoint Member
    Join Date
    Aug 2003
    Location
    KL
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    Quote Originally Posted by firepages
    basically yes, log user activity to a table and cleanup that table periodically , 10 seconds seems a bit extreeme though, I would run garbage collection whenever someone logs in?
    Oh ya i only need to check if a user need to be log out when some one login since the purpose is to avoid double login and not to time out a single login-ed user. That eliminates the cron job!

  6. #6
    SitePoint Member
    Join Date
    Aug 2003
    Location
    KL
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Quote Originally Posted by lastcraft
    Hi...
    It is a bit untidy to have the login recorded in two places. Have a look yours, Marcus
    Two places? The login will be recorded into a user table. Something like this

    member_tbl
    -------------
    user_id
    login_dt
    logout_dt
    active_dt

    When a user login,
    if logout_dt has a valid value
    {
    grant access
    update login_dt to current time and set logout_dt to null
    }
    else
    {
    inactive_dt = current time - active_dt
    if inactive_dt greater than say 30 minutes
    {
    grant access
    update login_dt to current time and set logout_dt to null
    }
    else
    {
    reject current login
    }
    }

    I see there's some problem with this method,
    If the user does not manually logout. Then another login with the same userid will depends on active_dt flag. How to update active_dt is another problem. Right now what i can think of is to update the active_dt flag whenever user browse a page.

  7. #7
    SitePoint Addict mr tinkles's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need a page that only allows any user to login once. Any subsequent login with the same username will be deny.
    not hard to do. just curious, if user login once, how do they login again? logout? aren't gonna have many users, if they can only login once.

  8. #8
    SitePoint Member
    Join Date
    Oct 2003
    Location
    Williamsburg VA
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by edwardkoo
    2) Run a cron job to check the login flag every 10 seconds to logout non-active user (user that has leave the page) or user that didn't logout properly due to system crashed and etc.
    You don't need a cron job. Every time a user visits a page, any page, record this in a field called, say, LastVisit. When the user tries to login, check this field. If it's within 20 minutes (or whatever your time is), assume that he's already logged in. Otherwise, assume the user as "logged out". There's no need to actively update the field after 20 minutes.

    Hope this makes sense.

    Norman


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
  •