Page 1 of 1

single side logon...

Posted: Mon Mar 03, 2003 3:59 am
by theclay7
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();

Posted: Thu Mar 06, 2003 12:48 pm
by rodrigocaldeira
You can do this with a query in a database each time you request the page, eg:

User A logon and his login is recorded into a table;
User B logon and verify if there is someone into the table;
if yes, delete the user and the User B login is recorded into the table.

Each request, verify if his login is into the table, and if not, redirect him to a error page....