SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to prevent duplicate login with session

    When username and password is correct. I register username is session. but the problem is I already login in my computer and can login again in another computer. How to prevent duplicate login?
    I live in Thailand. My English grammar not well.

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when someone logs in you could have a seperate table to store their login info.
    so, when someone goes to login, check the login table to see if the user info is there.
    if it is say they're already logged in somewhere else.

    just make sure you delete the info from that table when they logout.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    Digital Warrior Renegade's Avatar
    Join Date
    Nov 2000
    Location
    Portland, OR
    Posts
    480
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem with that, is that a lot of people won't click the logout button. They just close the window. Therefore, the login data stays in there indefinately.

    So now what are you going to do? *shrug*
    --There's my 1.5 cents, now where is my change!?!?

  4. #4
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had the logout problem too... but with the help of some guru's on this forum and php.net's mailing list, I now have a nice new CRON script working that selects populated session id's with a timestamp older than 1 hour. I figured that most people aren't logged in for more than 1 hour. I added a little field in the DB to determine whether or not the cron script or the person logged out so the next time they log in, a little message pop's up reminding them to properly logout.

    I can give you some more details/script if you'd like.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  5. #5
    SitePoint Zealot trigger8's Avatar
    Join Date
    Nov 2000
    Location
    Dallas, TX
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi jdulberg,

    I'm interested in those scripts...can you send it to me?
    Thanks!
    Trigger8

    **************************
    I killed a 6-pack just to watch it die!

  6. #6
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem... your script will obviously need to be customized for your particular system/db setup but here goes.

    I just called the file killsessions.php

    PHP Code:
    <?php
    //load the db connection info
    require("common.php");
    $date date("F j, Y, g:i a");

    $sql="select id, DATE_FORMAT(time_in, '%M %d, %Y, %r') AS unixdate from logged_in WHERE (date_add(time_in,interval 1 hour) <= now()) AND (time_out='-')";
    $result mysql_query($sql);
    $num_rows mysql_num_rows($result);
    if (
    $num_rows 0) {
        while (
    $a_row =mysql_fetch_array ($result)) {
            
    extract($a_row);
            
    $dump "UPDATE logged_in SET time_out = '$date', session='', time_in=time_in WHERE (logged_in.id='$id')";
            
    $r mysql_query($dump);
        }
    }
    ?>
    And my table structure for logged_in is:

    CREATE TABLE logged_in (
    id tinyint(4) DEFAULT '0' NOT NULL auto_increment,
    session varchar(100) DEFAULT '0' NOT NULL,
    time_in timestamp(14),
    time_out varchar(50) DEFAULT '-' NOT NULL,
    KEY id (id)
    );

    Basically, when the user logs in, their session is added and their login time (time_in) is added -- time_out is set to "-" since they have not logged out and the killsessions script looks for that character and a populated session.

    Then just run killsessions.php from CRON at whatever interval you choose.

    Hope that gets you started.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  7. #7
    SitePoint Zealot trigger8's Avatar
    Join Date
    Nov 2000
    Location
    Dallas, TX
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot!
    Trigger8

    **************************
    I killed a 6-pack just to watch it die!


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
  •