Forum Moderators: open

Message Too Old, No Replies

Unique variable

How unique are session variable

         

Numpty

3:38 pm on Nov 8, 2004 (gmt 0)

10+ Year Member



I need to use a unique variable to track a user whilst browing a site.

I am considering using the session variable that the Windows server creates automatically - e.g. CBLPPDLDNJPAIFNAHDMLKOKC.

How unique is this variable? - I'm not sure how the server generates it.

My plan is to write the variable to a database along with other information, then recall the info later in the session using the session variable. What are the chances of getting a duplicate in the database? I'm assuming that it is almost impossible, but I thought Id check here first.

Xoc

6:37 pm on Nov 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, it is close to impossible to get a duplicate. Realize that if the session expires, so does the session id, and it is unlikely, but it could be reused after a while, so you shouldn't use this as a long term primary key. But for use during a session, it is just fine.

mcfly

11:06 am on Nov 22, 2004 (gmt 0)

10+ Year Member



Numpty,

To give you an idea of how unique the session id would be, you can work out how many different possible combinations of the session id there are with 26 to the power of (number of characters).

So for a 22 character id as in your example, there are 26^22 = 1.4x10^31 possible values. Although it's possible that two concurrent users might get the same random session id value, even if you had a million users on the site at once the chances of it happening would less then one in a billion billion!