View Full Version : single side logon...

03-03-2003, 10:58 AM
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?


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";

$uid = $_POST["uid"];

include "ssolib/sso_cache.inc";

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


if ( ( $ret[0] == '00000000000000000000000000000000' ) ||
( $ret[1] < time() - 5 * 60 ) ) {
$_SESSION["logon"] = $uid;
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";


03-03-2003, 06:42 PM
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.

03-06-2003, 03:15 PM
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?

03-07-2003, 03:06 AM
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