Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    single side logon...

    i am trying to write a code that would allow single logon only...
    if person A is logon at time 00:00 and person B is logon at time 00:01, person A will be automatically logout...

    how can i do that with session?

    the following code would tell person B that he cannot logon due to person A has already logon....how should i implement from this?

    <?php

    if ( $_SERVER["REQUEST_METHOD"] <> 'POST' ) {
    echo "<form method=\"POST\" action=\"" . $_SERVER["REQUEST_URI"] . "\">\n";
    echo "UID <input type=\"text\" name=\"uid\">\n";
    echo "<br>please insert a number less than 102800<br>\n";
    echo "<input type=\"submit\" value=\" Logon \">\n";
    echo "</form>\n";
    include "menu.php";
    exit;
    }

    $uid = $_POST["uid"];

    include "ssolib/sso_cache.inc";

    $sso = new sso_cache;
    $sso->open();
    $ret = $sso->read($uid);

    session_start();

    if ( ( $ret[0] == '00000000000000000000000000000000' ) ||
    ( $ret[1] < time() - 5 * 60 ) ) {
    $_SESSION["logon"] = $uid;
    session_register('logon');
    echo "<br>session is registered - your sid = " . session_id() . "<hr>\n";
    echo "My uid : " . $uid . "<br>\n";
    $sso->write($uid, session_id());
    } else {

    echo "DEBUG Current time is " . strftime("%T", time()) . "<br>\n";

    echo "Sorry, you was logged-on from : at " . strftime("%T", $ret[1]) .
    " with sid " . $ret[0] . "\n";;
    echo "You try to logon again, we must clear your session<p>\n";
    session_destroy();
    }

    $sso->close();

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    What you need to use is a file or database. Can't share information among sessions. Kind of defeats the purpose of sessions don't ya think?

    Just store a value in a file or database indicating that someone is logged in then check that value each time someone logs in. When they log out then reset the value. Of course if they do not log out then I suppose everyone else that wants to log in is just screwed.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just an idea.
    Supposing that PHP, or the http-server running it, have read/execute access to the folder where the sessions are stored, and supposing that everytime a session expires or is ended through session_destroy() the file corresponding to it also dies (this means you have to set a maximum time so the session expires eventually), you could do the following:

    1. check if there are any files in the folder where the sessions are stored, using session_save_path(). Just do a simple open_dir()/read_dir() pattern and if file count is 0 then no sessions are active.

    2. if no sessions are active, you can start your new session. Otherwise, the user is refused.

    One thing I didn't understand was the following. Person A and Person B on your example were using the same Username/Password or did they have different Usernames/Passwords?

  • #4
    New Coder
    Join Date
    Feb 2003
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    same username and password...

    actually i fix it with using hash table...

    i read in the cache and write it to update who is the most updated person...

    thx anyway


  •  

    Posting Permissions

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