hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Which is the best way to track user sessions?
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Which is the best way to track user sessions?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 06-05-2008, 06:34 AM
Lord Northern Lord Northern is offline
Junior Guru
 
Join Date: Feb 2006
Location: Israel
Posts: 187

Which is the best way to track user sessions?


Hey.
I'm trying to figure out how to write a better way for me to track user sessions on my website.

What I do so far is this:
When the user logs in, I generate a 64 char long string and store it in the db and a cookie of the user.
The database table that stores this string also stores the user id (to be able to know whose this session ID is) and an exact time.
Every time a user clicks on a page or does something on the site, the script loads the content of that cookie, then runs through the sessions table in the database to find a session ID like the one stored in the cookie.
If it manages to find it, it will do the following:
If date of last activity is less than 5 minutes, it'll simple return the user ID and update the last activity to the current second and the script will go on.
If the last activity was more than 5 minutes ago, it'll still return user ID but also change the session id both in the cookie and the db (a kind of a way to relogin but the user doesn't feel it).

I think my system isn't exactly a good one because someone may try to run a script that will be sending these strings and may stumble upon a correct ID.

So, I wanted to know: how is this stuff usually handled in professional projects like I dunno, joomla/phpbb and other professional sites?

thanks

Reply With Quote


Sponsored Links
  #2  
Old 06-05-2008, 06:56 AM
djorgensen djorgensen is offline
Web Hosting Master
 
Join Date: Jun 2006
Posts: 1,003
Is this for PHP, Java or ASP.NET?
Or something completely different

__________________
--
Damien Jorgensen
www.permoveo.ltd.uk

Reply With Quote
  #3  
Old 06-05-2008, 07:11 AM
Lord Northern Lord Northern is offline
Junior Guru
 
Join Date: Feb 2006
Location: Israel
Posts: 187
Oh, my bad. I forgot to say. It's PHP/MySQL.

Reply With Quote
Sponsored Links
  #4  
Old 06-05-2008, 07:46 AM
sasha sasha is offline
Hail Eris !
 
Join Date: Oct 2002
Location: Canada
Posts: 3,100
Only thing you are missing there is something that would clean up database from all sessions older then, lets say 20 minutes. That gives users 15 minutes of inactivity before they are completely logged out. Chance of someone guessing random 64 characters string in 20 minutes time window is none. Only possible problem is if the string is truly random. If someone registers 5 user accounts and logs with all of them, could he guess what logic you use to generate those strings?

That all being said, you are reinventing the wheal. Everything you are doing there can be done using php's builtin session handling.

Reply With Quote
  #5  
Old 06-05-2008, 07:52 AM
Lord Northern Lord Northern is offline
Junior Guru
 
Join Date: Feb 2006
Location: Israel
Posts: 187
So you're saying it's just better to go with the sessions in php?

Reply With Quote
  #6  
Old 06-05-2008, 08:28 AM
sasha sasha is offline
Hail Eris !
 
Join Date: Oct 2002
Location: Canada
Posts: 3,100
Quote:
Originally Posted by Lord Northern View Post
So you're saying it's just better to go with the sessions in php?
I do not know what your project is about so I cannot tell. There is more then one way to do anything in PHP. For an example you can retrieve remote http file using sockets or you can just get it with file_get_contents. There is time and place for both of those approaches.

What you did is nice exercise but you have to ask yourself if it provides you anything that PHP builtin session handling does not. If it does not - use builtin stuff, it will make your code easier to understand and maintain.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Super Charge Your Trial Program Blog 2013-05-16 09:48:11
Cloud Expo 2013 Web Hosting Events 2013-04-24 17:21:38
DreamHost to Host First Ever DreamCon User Conference in August Web Hosting News 2013-01-23 14:09:22
Email Security Firm eleven Launches New User Interface Web Hosting News 2011-10-06 17:39:13
HostingCon Day 1 Blog 2011-08-08 22:53:21


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?