Session Vars

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Session Vars

Post by Todd_Z »

I am wondering how, based on a unique numeric ID, to never allow two simultaneous sessions with the same ID. Currently there is no row in a table that keeps track of the sessions, its simply using the php sessions functions. Is this a mistake? Should I store all session information in tables?
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

So you're currently implementing your own session handling function or you're setting your own unique session ID? I would think that PHP's default session handling has error checking for this sort of thing, OTOH if you're setting your own session ID value, something like

Code: Select all

$sid= md5(uniqid(mt_rand(), TRUE));
session_id($sid);
Should be sufficient to eliminate identical current sessions, but you never know. If you create a database session handler, use the above uniqid() method along with UNIQUE indexed column to make sure it's always unique.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Thanks bdlang,

Now that I'm going over it in my head, its a much better idea for so many reasons to keep track of sessions in tables.
Post Reply