Creating a Unique Basket ID

Results 1 to 2 of 2

Thread: Creating a Unique Basket ID

  1. #1
    Join Date
    Dec 1969

    Default Creating a Unique Basket ID

    Can someone please tell me if the following code is sufficient to overcome the problem of 2 users getting the same basket id?<BR>I want to use this id to create a cookie so that a user&#039;s basket can be identified if they have not logged in.<BR>I was going to use the session.sessionID together with a date/time stamp, however i have settled for this option. Are there any reasons why i shouldn&#039;t do it this way?<BR>One more thing, do you think i sould put this in the global.asa file (with some slight changes) or just in the files where i need them?<BR><BR>Thanks.<BR><BR>Function GenerateBasketID()<BR><BR> Dim oConn<BR> Dim oRs<BR> Dim BasketID <BR><BR> Set oConn = Server.CreateObject("ADODB.Connection")<BR> Set oRs = Server.CreateObject("ADODB.Recordset")<BR> oConn.Open "DSN=test" <BR><BR><BR><BR> Application.Lock <BR><BR> oConn.Execute("UPDATE BasketSession SET BasketSessionID = BasketSessionID + 1") <BR> oRs.Open "SELECT BasketSessionID FROM BasketSession", oConn<BR> BasketID = Right( "00000000" & oRs("BasketSessionID"), 8 ) <BR><BR> Application.Unlock <BR><BR><BR> oRs.Close<BR> oConn.Close<BR> Set oRs = nothing<BR> Set oConn = nothing<BR><BR> GenerateBasketID = BasketID<BR><BR>End Function

  2. #2
    Join Date
    Dec 1969

    Default RE: Creating a Unique Basket ID

    There are lots of ways to create unique numbers to ensure that two users do not have the same session variables. Some ideas include:<BR><BR>&#060;% Request.ServerVariables("REMOTE_ADDR") %&#062; which almost certainly has to be unique.<BR><BR>Somtimes, I convert now() into a variable with a little ditty like this:<BR>&#060;%nw = now()<BR>Do While InStr(1, nw, " ")<BR> nw = Replace(nw, " ", "")<BR>Loop <BR>Do While InStr(1, nw, "/")<BR> nw = Replace(nw, "/", "n")<BR>Loop<BR>Do While InStr(1, nw, ":")<BR> nw = Replace(nw, ":", "n")<BR>Loop<BR><BR>%&#062;<BR><BR>I am not an expert on what you are trying to do, I have never worked with shopping carts. But maybe this will give you some ideas.<BR><BR>Good luck!<BR><BR>Edward<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts