gcastillo
Posts: 45
|
| Posted: 06/20/2008, 5:31 AM |
|
Hello,
I have an application in CCS 4 (php) and want to programme that a user could login an alone time to the system.
That is to say, if a user this one connected to the system in a computer and he tries to access in another computer the application send a message of mistake of which it is not allowed to access 2 times to the system from different equipment.
Do you Can give me some suggestion as do this?
From already thank you very much.
Giovanni
_________________
Giovanni
|
 |
 |
gcastillo
Posts: 45
|
| Posted: 06/21/2008, 2:00 AM |
|
Hello,
Sorry, I need to implement this in my application and do not find like to do it. Someone might help giving me ideas wherefrom to search or to receive documents to be able to realize it.
Thank you very much
Giovanni
_________________
Giovanni
|
 |
 |
datadoit
|
| Posted: 06/21/2008, 8:30 AM |
|
The design concept:
* Create a log table that holds the user's id, a timestamp, and the
user's IP.
* When user logs in, check the log table to see if the user has logged
in recently from the same IP. If so, then either let them know or just
not allow the login.
* When the user logs in after passing the above, write a new log entry.
|
|
|
 |
gcastillo
Posts: 45
|
| Posted: 06/21/2008, 2:39 PM |
|
Thank you very much datadoit !
I am going to realize tests with the idea that you indicated me.
I have a doubt, understand that when the user logout, I must update my log table indicating that he left the system.
But in case the session expires, since I can establish it to update my table of log?
Again thank you for your help,
Giovanni
_________________
Giovanni
|
 |
 |
datadoit
|
| Posted: 06/21/2008, 6:47 PM |
|
That part gets a little tricky, since many folks just close the browser
window instead of choosing to "log out".
To get around that, you could update your log table when the user enters
certain pages in your site (Page BeforeShow insert into the log). The
log is used to track if they're 'active' or not. If, perhaps, 10
minutes have elapsed since their last activity, then they're considered
logged out.
In your login form's Login button's server OnClick, add custom code:
<code>
global $DBConnectionDB;
if ($Login->password->GetValue() != "") {
if ($DBConnectionDB) {
$SQL = "INSERT INTO log_users (log_ip, log_userid, log_timestamp,
log_last_active) VALUES (" . CCToSQL($_SERVER['REMOTE_ADDR'], ccsText) .
"," . CCToSQL(CCGetUserID(), ccsInteger) . ", NOW(), NOW() )";
$DBConnectionDB->query($SQL);
}
else {
Print "Fatal error. Bad connection.";
}
</code>
In each of the menu items we call the function LastUpdate(), which we
locate in the Common.php file:
<code>
//Common function to keep track of updates made by users.
function LastUpdate()
{
$db1 = new clsDBConnectionDB();
$db2 = new clsDBConnectionDB();
$SQL1 = "SELECT MAX(log_id) AS log_id FROM log_users WHERE log_userid="
.. CCGetSession("UserID");
$db1->query($SQL1);
$Result = $db1->next_record();
if ($Result) {
$SQL2 = "UPDATE log_users SET log_last_active=NOW() WHERE
log_id=".$db1->f("log_id");
$db2->query($SQL2);
$db2->close();
}
$db1->close();
} //End of function LastUpdate().
</code>
The structure of the log table is:
log_users
---------
log_id (INT, 9, auto-increment)
log_userid (INT, 9)
log_timestamp (DATETIME)
log_ip (CHAR, 15)
log_last_active (DATETIME)
|
|
|
 |
gcastillo
Posts: 45
|
| Posted: 06/21/2008, 9:38 PM |
|
Thank you very much Datadoit!!
A very explicit example, thank you for sharing it with me.
I am going to implement it in my project.
Cordial regards
_________________
Giovanni
|
 |
 |
|