473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Preventing multiple Users from logging into the same account at the same time

Hi all,

users usually have usernames and passwords, and can log in to many maches at once withe same details. What I want to do is restrict them to only one machine if they have already LOGGED-ON on one machine, any attempt to LOG-IN again to another they get kicked out or have a Pop up telling them they already LOGGED-ON to another machine.

All help will be greatly appreciated.
Thanx
Sep 4 '07 #1
12 8265
nathj
938 Expert 512MB
Hi all,

users usually have usernames and passwords, and can log in to many maches at once withe same details. What I want to do is restrict them to only one machine if they have already LOGGED-ON on one machine, any attempt to LOG-IN again to another they get kicked out or have a Pop up telling them they already LOGGED-ON to another machine.

All help will be greatly appreciated.
Thanx
Hi mankolele,

The way I would do this is an extra record against the user credentials. So when a user logs in you update the record to show that they are logged in.

Also when a user tried to log in you check this field and if they are already logged in you tell them this.

In addition to this it would be worth having the session timeout after a period of inactivity. this would mean that if they close the browser but don't log out they are eventually logged out automatically.

When a user logs out or the session is killed you set the record to show that they are not logged in.

In this way you can ensure that they only log in once. As the data is stored on the server it would work across machines and platforms as well.

Hope this helps
Cheers
nathj

PS This has given me an idea to improve my own site - thanks!
Sep 4 '07 #2
I have a table where I am doing that but my block is that all user are taken as id 1 where I end up not being able to identify who is who.
Sep 4 '07 #3
nathj
938 Expert 512MB
I have a table where I am doing that but my block is that all user are taken as id 1 where I end up not being able to identify who is who.
Hi mankolele,

Is there anything within in the table can uniqwuely identify a given user - username or email address for example? This could then form the basis of your query.

For good data design there should be someone of uniquely identifying a given user at any time.

Cheers
nathj
Sep 4 '07 #4
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem.

Heya, mankolele.

Try creating a database table that stores login sessions.

In this table, each session gets an ID (primary key). Also save the User's ID and an expiration date.

The expiration date should be a timeout value, so something like 15 minutes from the current time.

Whenever somebody tries to log in, check to see if there is a valid (unexpired) session for that User. If one already exists, deny access.

If there are no active sessions, log the User in and create a new entry in the login sessions table. Also save the ID of the login session in the User's _SESSION. Since each _SESSION is unique per client (or in theory anyway), this ensures that only the machine that had that _SESSION could be logged in for that account.

When the User is browsing on the site, don't forget to extend the expiration time of the login session!

When the User logs out, delete the record from the login sessions table.
Sep 4 '07 #5
Ooook I'm lost plain lost, I understand the theory myself but.................................... I don't know.
Sep 5 '07 #6
nathj
938 Expert 512MB
Ooook I'm lost plain lost, I understand the theory myself but.................................... I don't know.
Hi,

I think the aim is this:

1. Have a table that stores when a user logs in. In the table store the date and time they logged in and when the session will expire

2. When a user logs in update the table and load the session variables.

3. Everytime a request is made by the user the session expiration time is moved on, so that from each activity the session will remain for 15minutes (as an example).

4. Whem the session has been inactive for 15+ minutes simply remove the record from the table and kill the session variables

5) If the user logs out properly do the same as in 4.

If a user is logged on to the system on one machine and then moves to a different machine when they log in again you can check the table for the user id. If it is there and the session is live you don't allow access but explain that they can only log in once.

I think this is the general idea. The only bit I'm a bit vague on is how to monitor session activity so I will be watching this thread closely.

I hope I have helped.

Cheers
nathj
Sep 5 '07 #7
Yeeee I finally managed to add all that up now one iusername has one access and every 15minutes are timed out from the table, which I am not sure if its good coz now the gap is opened I think.

Now my other concern is when they click on LOG-OUT , yes I need to DELETE from table WHERE user = "", yes this happens on the MySQL screen but I can not somehow pass that variable in PHP.
Sep 5 '07 #8
nathj
938 Expert 512MB
Yeeee I finally managed to add all that up now one iusername has one access and every 15minutes are timed out from the table, which I am not sure if its good coz now the gap is opened I think.

Now my other concern is when they click on LOG-OUT , yes I need to DELETE from table WHERE user = "", yes this happens on the MySQL screen but I can not somehow pass that variable in PHP.
Hi,

My suggestion would be to have an auto-increment field in the table that stores the logon details. then store this number in the $_SESSION. When they log out you can use the $_SESSION variable in your SQL query n php.

Cheers
nathj
Sep 5 '07 #9
What a relief all is well finally....Thank you with all your help. One more thing when capturing the LOG-IN data I see I get the previous entry not the present one I am at, what am I missing for me to get the last details not present username.
Sep 5 '07 #10
nathj
938 Expert 512MB
What a relief all is well finally....Thank you with all your help.
Always happy to help
One more thing when capturing the LOG-IN data I see I get the previous entry not the present one I am at, what am I missing for me to get the last details not present username.
I'm gonna need a bit more for this - have you got some code you could show us? This would be a useful part of a further explanation of the final probelm.

It may be a refresh problem - off the top of my head, I ahd something similar with $_SESSIONs once. I can't remember now how I fixed it but if you post some code it may jog my memory.

Cheers
nathj
Sep 5 '07 #11
[PHP]
session_start();

$connection = mysql_connect("localhost", "xxxx", "xxxxxxx");
$select_db = mysql_select_db("xxx", $connection);
$query = mysql_query ("SELECT username,password,id FROM members where id ='".$_SESSION["id"]."'", $connection);

$timestamp = time();
$activity = "Log in";


if(isset($_COOKIE['ID_my_site'])){

$_SESSION['log_admin']=$data['ID_my_site'];
$_SESSION['admin_access']=$data['id'];


$name = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT username,password,id FROM members WHERE id = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
header("Location: fail.php");
} else {
header("Location: 1.php");
//header("Location: welcome.php");
}
}

}

if (isset($_POST['submit'])) {

$usercheck = $_POST['username'];
$check = mysql_query("SELECT user FROM logged WHERE user = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, '.$_POST['username'].' you already LOGGED ON..... on another machine <a href="index.html">Back</a>');
}






if(!$_POST['username'] || !$_POST['password']) {
header("Location: fail.php");

}

$check = mysql_query("SELECT username, password,name,surname FROM members WHERE username = '".$_POST['username']."'")or die(mysql_error());

//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
header("Location: fail.php");

} else {

while(list($username, $password,$name,$surname) = mysql_fetch_array( $check ))
{
$_POST['password'] = stripslashes($_POST['password']);
$password = stripslashes($password);
$_POST['password'] = md5($_POST['password']);

if ($_POST['password']!= $password) {
header("Location: fail.php");

} else {
$_POST['username'] = stripslashes($_POST['username'] && $_POST['password'] == $password);
$hour = time() + 3600;
setcookie("Use", $username);

setcookie("Name", $name);
setcookie("sur", $surname);

if ($rowsAffected != -1) {

$query ="INSERT INTO logged (lastactive,activity,user)
VALUES ('".$timestamp ."','".$activity."','".$_COOKIE['Use']."')";
$result = mysql_query ($query, $connection) OR die("Error ".mysql_errno()." : ".mysql_error());
$rowsAffected = @ mysql_num_rows($result);

}//close rows Affected
else if ($rowsAffected == -1 ){

}
header("Location: welcome.php");

}

}
}

}

[/PHP]

Is the code for where I get the login details .
Sep 6 '07 #12
nathj
938 Expert 512MB
Hi mankolele,

I have read over the code and there is nothing that jumps out as the cause of the problem.

however, it has served to jog my memory a little. I mentioned previously that I had a php script that was returning the previous session values. In my case it was on a captcha image - so even if you could see the text it was no good you had to see the previous set - fixed that though.

In my case the trouble was that I was setting the $_SESSION variable too late in the process. It may be that you need to play around with where the $_SESSION variables etc are set.

I'm sorry to be a bit vague but that's all I can think of for this one. I hope it helps - even in some small way.

Cheers
nathj
Sep 6 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: BenM | last post by:
Description: I would like to prevent a user from logging in with their user/password combination on a different computer or even a different browser window, if they are already logged in. I have...
1
by: Karthik | last post by:
Hi, I have a website running on ASP.Net on IIS 6.0. This website has more than 10000 users login everyday. At times the users login with the same user name and password more than once at the...
6
by: mark | last post by:
I have an asp.net ecommerce web application on a remote web server. I'm using an Access database on the back end. I've notice a few strange things. When I mimic an multiple user environment by...
10
by: Conformix Sales | last post by:
Any thought about how can I stop a user from logging into the application multiple times. I am using forms authentication.
6
by: anoj | last post by:
Hi All i need to prevent multiple logins from the same user at the same time. what is the best way to do this . How can i detect if a user closes the browser window without logging out so tht...
10
by: et | last post by:
I have an asp.net program that uses a connection string, using integrated security to connect to a sql database. It runs fine on one server, but the other server gives me the error that "Login...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
18
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
3
by: cowznofsky | last post by:
We looking at creating a web application where a login Id can only be used once at a time. The idea is that this is a paid site, and we're pricing it by the number of seats. So if we create 3...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.