Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unique ID for Every Session 1

Status
Not open for further replies.

bowettwow

Programmer
Aug 1, 2002
57
GB
Dear All,

When someone logs on to my transactional site I want to assign them an "Order Number" (which is unique) when they start a session. I assume I need some code in my Global.asa. Whats the easiest way to do this.

Cheers,

BowettWow.
 
why not use the session id that asp creates for each session - session.sessionID?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
the sessionID value will give you this

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924[/sub]
onpnt2.gif
 
Will the SessionID always be unique or will it repeat ID's over a period of time (perhaps after a restart of the server)?
 
They are unique

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
I dont mean to press this point but I've just read in a book on ASP that:

"the session ID should not be used as a primary key in a database because because it may not always be unique. For example if the Web Server is restarted, the server may assign a sessionID that was previously assigned to a different user."

Has IIS changed in recent versions to correct this? Any thoughts?
 
Please correct me if i'am wrong but I do try
I have never done this before but here goes!!!!!!!!

In the global asa put the following sub:

Sub Session_OnStart

end sub

This will be run when a new session is created.
Then create a text file which contains a 0

Then use the file system object in the sub to read from the text file. After it has been read cast it to a Long.This will be you id.Then assign it to a session variable.
Write this value back after you have incremented it to the text file after you have deleted the old one.
Well thats sort of the what I think should happen.
Hope it works!

Corne'
#-)
 
Sometimes the simple solutions can be the best :)
 
bowettwow
you had not mentioned anything in regards to a database prior to the last post. although I think the chances of the sessionID being duplicated are slim to none it would be senseless to use anything but a autonumber for your primary ID in the DB. That is what it is for! It's safe, stable and conventional database design.



____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
bowettwow : If you have a Database, onpnt's idea will definatly work the best. It will cut the overhead of reading and writing to the text file as well as the creation of the FSO object.100% faster and safer.

Corne'
#-)

 
But how would I pass the unique id to a session variable from an autonumber in my database. I'd somehow have to add a record to the database and then read what autonumber the database assigned it - how could I do this?
 
bowettwow:
You don't have to add a new record to the table just add 1 to the last recordnumber.

Maybe somebody knows a quick way to do this so that you don't have to query the database for the last record?

Corne'
#-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top