Building up cookie and splitting

Results 1 to 2 of 2

Thread: Building up cookie and splitting

  1. #1
    Join Date
    Dec 1969

    Default Building up cookie and splitting

    Hi Everyone,<BR><BR>I&#039;m wondering if one of your pro&#039;s can offer a newbie a little assistance if you have the time. Allow me to explain what I am trying to do:<BR>I am trying create an advertising system that only shows a banner that a user has not seen in the last 24 hours. So far, When a banner gets shown I am setting a cookie to the value of the banner ID. The next time to code is executed, it reads the cookie and shows a different banner.<BR>My problem is, I need to build up the cookie with ID&#039;s, and somehow split them so the recordset can select an ID that is not in the cookie. I have read alot of article and am still stumped on how I can possibly do this.<BR><BR>Here is an example of my code so far:<BR>=====================================<BR>< BR><BR>&#039;Check to see if user has already seen a banner by looking for cookie<BR>If Request.Cookies("BannerID")="" Then<BR>&#039;Customer has not seen a banner yet<BR>varSeenit=0<BR>Else<BR>&#039;ID of banner seen<BR>varSeenit=Request.Cookies("BannerID")<BR>E nd If<BR>&#039;**************************<BR>&#039;va rSeenit (above) may look somethig like this: 12&#124 65&#124 23&#124 13<BR>&#039;I need something here to split to cookie.<BR>&#039;The cookie may look like this 12&#124 65&#124 23&#124 13 etc<BR>&#039;And then I need the code below to be able to read the id&#039;s and a select a record that does not exist in varSeenit<BR>&#039;**************************<BR>< BR>&#039;Recordset to select a banner - any banner as long its not the same as the cookie<BR>set rsRedirect = Server.CreateObject("ADODB.Recordset")<BR>rsRedire ct.ActiveConnection = MM_connTraffic_STRING<BR>rsRedirect.Source = "SELECT WebsiteURL, WebsiteHits, BannerID FROM tblCustomer WHERE WebsiteHits &#060; HitLimit AND BannerID &#060;&#062; " + Replace(varSeenit, "&#039;", "&#039;&#039;") + " "<BR>rsRedirect.CursorType = 1<BR>rsRedirect.CursorLocation = 2<BR>rsRedirect.LockType = 3<BR>rsRedirect.CacheSize = 8<BR>rsRedirect.Open()<BR>rsRedirect_numRows = 0<BR><BR>&#039;Now randomize the banners we have left in the recordset<BR>sub moverandom(rec)<BR>Randomize Timer <BR>rec.MoveFirst<BR>rec.Move Int(RND*Cint(rec.RecordCount))<BR>end sub<BR>moverandom rsRedirect<BR><BR>&#039;Set a cookie to make sure it is a unique banner next time<BR>Response.Cookies("BannerID")=""&Request.Co okies("BannerID")&"&#124"&rsRedirect.Fields.Item(" BannerID").Value&""<BR>Response.Cookies("BannerID" ).Expires=Date()+1<BR><BR><BR>&#039;And then show banner............<BR>**************************** ****<BR><BR>If anyone can see how I could achieve this, or can suggest any alternative way, I&#039;d certainly be very grateful.<BR><BR>Thanks for your time,<BR>Marcus.<BR><BR><BR><BR><BR><BR><BR><BR><B R><BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Believe it or not...ASPFAQs...

    In the category Databases, Queries. The first one:<BR><BR><BR><BR>If you will put the values into your cookie separated by commas instead of vertical bars, you will *NOT* need to (or want to) split the cookie apart to use it in the SQL statement!<BR><BR>If the cookie contains "12, 65, 23, 13" then you can just do<BR><BR>SQL = "SELECT ... WHERE ... BannerID NOT IN ( " & varSeenIt & ")"<BR><BR>How do you avoid getting an extra &#124 (or, now, a comma) on the front of the cookie value? I think the answer is, you don&#039;t! If you simplify your code just a little:<BR><BR>&#060;%<BR>Response.Cookies("Banner ID")= varSeenIt & "," & rsRedirect("BannerID")<BR>%&#062;<BR><BR>See, when the cookie *was* blank, you gave varSeenIt a value of "0", yes? And doing "SELECT...WHERE fld NOT IN (0)" works just fine if you don&#039;t really have any field with a value of 0 (if you do, initialize varSeenIt to "-1" instead). So after you select (say) random record 13, the cookie string will become "0,13". But, again, with no record numbered 0 it will work fine to say "SELECT...WHERE fld NOT IN (0,13)" won&#039;t it?<BR><BR>Simplify, simplify, simplify.<BR><BR>And can you explain the point of doing ""& and &"" at the front and end of building that cookie string?<BR><BR>And finally...<BR><BR>*NEVER* use + to do string concatenation in VBS! NEVER! On rare occasions you will be surprised by the results...when + does addition instead!<BR><BR>I refer to this code:<BR>rsRedirect.Source = "SELECT... BannerID &#060;&#062; " + Replace(varSeenit, "&#039;", "&#039;&#039;") + " "<BR><BR>And, looking at that again, why did you think you needed to replace &#039; with a pair of &#039;s in that? YOU build the cookie, yes? And YOU don&#039;t put &#039; marks into it, do you? The only reason to do such a replace is when you are getting text from a form field and the user might have typed in a &#039; mark. That&#039;s all.<BR><BR> <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