PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old June 19th, 2004, 03:49 PM
bob23 bob23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 bob23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Preventing multiple logins

I hope you can help me solve a tricky problem. I have a basic login script that i use to secure a website for members only. To solve the problem of individuals sharing password to access the service i am trying to come up with a php (perhaps using mysql too) script to prevent other individuals accessing the service from another computer if the account is already being used by another user ie. one user logged in at a time with an individual username and password

I hope you can all help, as i am now tearing my hair out

regards

bob

Reply With Quote
  #2  
Old June 19th, 2004, 07:38 PM
pocketsized pocketsized is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Brunei
Posts: 26 pocketsized User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Although I've never tried anything like this yet, I'd suggest assigning and storing a few variables in the database:

1. Session or Cookie variable.
2. The user's IP address.
3. Date/Time of last activity.

When the user logs in, store his IP address along with the corresponding session/cookie variable in the database in the same row as his unique identifier (e.g. his user name or a unique user id number). Everytime a user logs in, check the session/cookie variable. If it is still valid (i.e. hasn't timed out) and if his IP address corresponds with the one in the database, he's logging on from the same terminal so allow him access.

What happens when another user tries to login using the same username & password before the first user has logged off? Since the session/cookie variables have already been set by the first user and stored in the database, check the IP address of this new user. Since it will be different from the IP address in the database, deny him access.

To ensure that this code properly works, you'll need proper functions to nullify the session/cookie variables as well as the IP addresses at proper times. One time is when the user logs out. Another instance is through a time out function based on when the user was last active (e.g. 1 hour of inactivity and the system logs you out)

Like I said at the beginning, I've never actually tried this before but this is how I'd do it. Still, I'd wait and see what others have to say.

Reply With Quote
  #3  
Old June 21st, 2004, 08:08 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Yeah, something along those lines should suffice, pocketsized. I've got something similar in production, though I just log out the earlier session if a new session is opened (say I was logged in here at work and then drove home and tried to login before my original session expired -- wouldn't want to lock myself out). Rather than storing IP addresses, I also just store the session id in the database and compare it against the cookie on the client machine. If my IP changes mid-session for whatever reason, I can still continue my session without interruption.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #4  
Old June 22nd, 2004, 04:43 AM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
the problem with that idear is! that if the user is behind a proxy ei a school. only one user from the whole school can be logged on.

Reply With Quote
  #5  
Old June 22nd, 2004, 07:26 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Right, that's why you use session_id and a cookie instead of IP address. We're behind a proxy at my work and this system works like a charm.

Reply With Quote
  #6  
Old June 22nd, 2004, 05:30 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
my point

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Preventing multiple logins


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway