473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

link tracker with cookie to stop repeat clicking

229 100+
Hi, I have this very nice link tracker script that works a treat.
The only thing is it doesnt restrict repeat clicking.

Is there a simple method to add a cookie feature to this so that people cannot vote twice. I prefer cookies over ip recording. Any pointers would be a great help.


Expand|Select|Wrap|Line Numbers
  1. %@ Language=VBScript %>
  2. <%
  3. Option Explicit              ' Never code without it!
  4. Response.Buffer = True       ' Make sure we can redirect later
  5.  
  6. ' The constants I use in this script...
  7. ' pulled directly from adovbs.inc
  8. Const adOpenForwardOnly = 0
  9. Const adOpenDynamic = 2
  10. Const adLockReadOnly = 1
  11. Const adLockPessimistic = 2
  12. Const adCmdText = &H0001
  13.  
  14. ' This needs to be ' for SQL Server and # for Access
  15. Const DATE_DELIMITER = "#"
  16.  
  17. Dim strName                  ' Friendlyname of the redirect
  18. Dim strId                  ' id the redirect
  19. Dim cnnLinkTracker           ' ADO objects
  20. Dim rsLinkTracker
  21. Dim strSQL                   ' SQL command building area
  22. Dim iRedirectId              ' id of the redirect for logging process
  23.  
  24. ' Get name of location to go to
  25. ' I simply call this name so to call the script it would look
  26. ' something like this:
  27. ' http://server/linktracker.asp?id=asp101
  28. ' where asp101 is the friendly id from the database
  29. strId = Request.QueryString("id")
  30.  
  31. ' Make it DB friendly just in case a ' got in somehow
  32. strId = Replace(strId, "'", "''")
  33.  
  34. ' Create a new connection
  35. Set cnnLinkTracker = Server.CreateObject("ADODB.Connection")
  36.  
  37. ' Your connection string goes here!
  38. ' This one expects an Access database in the same place as this script
  39. cnnLinkTracker.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
  40.     Server.MapPath("/xxxxxxxxxxxx"), "", ""
  41.  
  42. ' Create a recordset
  43. Set rsLinkTracker = Server.CreateObject("ADODB.Recordset")
  44.  
  45. ' Get the record we're looking for by passing it the name
  46. ' we got from the QueryString.  I'm prebuilding the SQL command
  47. ' to make it easier to debug if we need to.
  48. strSQL = "SELECT PostCard, Headline  FROM tblGreet " & _
  49.     "WHERE PostCardID=" & strId & ";"
  50. ' Quick and dirty debugging when something goes wrong.
  51. 'Response.Write strSQL
  52.  
  53. ' Send the command to the database to get the appropriate records
  54. rsLinkTracker.Open strSQL, cnnLinkTracker, _
  55.     adOpenForwardOnly, adLockReadOnly, adCmdText
  56.  
  57. ' If we got back any results then we know where to send them
  58. ' o/w I just send them to our home page for lack of a better
  59. ' place to send them.
  60. If Not rsLinkTracker.EOF Then
  61.     ' Get redirect Id # from recordset
  62.     iRedirectId = rsLinkTracker.Fields("PostCard").Value
  63.  
  64.     ' Get location to send the user to
  65.     strName = rsLinkTracker.Fields("Headline").Value
  66.  
  67.     ' We've got all the info we need so close our recordset
  68.     rsLinkTracker.Close
  69.  
  70.     ' I now recycle the recordset for the logging process.
  71.     ' Lots of people would argue with me about this, but I
  72.     ' know I'm doing it and this is my code so if you don't
  73.     ' like it feel free to change it, but I'm not going to!
  74.  
  75.     ' Start logging process
  76.  
  77.     ' Build out SQL String ahead of time.
  78.     ' This should get us the record containing the information
  79.     ' for the selected link for today's date if one exists.
  80.     strSQL = "SELECT link_id, hit_date, hit_count " & _
  81.         "FROM tblLinkTrackerLog " & _
  82.         "WHERE link_id = " & iRedirectId & " " & _
  83.         "AND hit_date = " & DATE_DELIMITER & Date() & DATE_DELIMITER
  84.  
  85.     ' Standard debugging step when something goes wrong!
  86.     'Response.Write strSQL
  87.  
  88.     ' Send the command.
  89.     rsLinkTracker.Open strSQL, cnnLinkTracker, _
  90.         adOpenDynamic, adLockPessimistic, adCmdText
  91.  
  92.     ' If it's EOF then it's the first hit of the day and we need
  93.     ' to add a new record o/w we simply update the existing hit
  94.     ' count of the record by adding one to it.
  95.     If rsLinkTracker.EOF Then
  96.         rsLinkTracker.AddNew
  97.  
  98.         rsLinkTracker.Fields("link_id").Value   = iRedirectId
  99.         rsLinkTracker.Fields("hit_date").Value  = Date()
  100.         rsLinkTracker.Fields("hit_count").Value = 1
  101.     Else
  102.         rsLinkTracker.Fields("hit_count").Value = _
  103.             rsLinkTracker.Fields("hit_count").Value + 1
  104.     End If
  105.  
  106.     ' Save changes to the data
  107.     rsLinkTracker.Update
  108. Else
  109.     ' If no match send em to our home page
  110.     strName = "/"
  111. End If
  112.  
  113. ' Close our recordset object
  114. rsLinkTracker.Close
  115. Set rsLinkTracker = Nothing
  116.  
  117. ' Kill our connection
  118. cnnLinkTracker.Close
  119. Set cnnLinkTracker = Nothing
  120.  
  121. ' Send them on their merry way using the location we got
  122. ' from the database!
  123. Response.Redirect "http://" & strName
  124. %>

Thanks
Richard
Mar 8 '08 #1
2 1610
fran7
229 100+
Hi, I got this cookie if clause done but it doesnt seem to work. I mean it doesnt stop someone clicking 100 times, it will record all 100. It is meant to, with the use of the cookie to stop after the first. Can anyone see why? Any help would be great.
Thanks
Richard


Expand|Select|Wrap|Line Numbers
  1.  ' Send the command.
  2.  rsLinkTracker.Open strSQL, cnnLinkTracker, _
  3.   adOpenDynamic, adLockPessimistic, adCmdText
  4.  
  5.     'Establish cookie for unique hit Counting
  6.  
  7.   Response.Cookies("Visited").Expires=date+1 
  8.   strVisited = Request.Cookies("Visited")
  9.  
  10.  ' If it's EOF then it's the first hit of the day and we need
  11.  ' to add a new record o/w we simply update the existing hit
  12.  ' count of the record by adding one to it.
  13.  
  14.  If rsLinkTracker.EOF Then
  15.   rsLinkTracker.AddNew
  16.  
  17.   rsLinkTracker.Fields("link_id").Value   = iRedirectId
  18.   rsLinkTracker.Fields("hit_date").Value  = Date()
  19.     rsLinkTracker.Fields("hit_count").Value = 1
  20.  
  21.     Response.Cookies("Visited") = "yes"
  22.     ' Save changes to the data
  23.    rsLinkTracker.Update
  24.  Else
  25.    If strVisited = "" Then
  26.         Response.Cookies("Visited") = "yes"
  27.         'Increment the visitor counter number by 1
  28.         rsLinkTracker.Fields("hit_count").Value + 1
  29.         ' Save changes to the data
  30.     rsLinkTracker.Update
  31.     End If     
  32.  End If
Mar 11 '08 #2
jhardman
3,406 Expert 2GB
How do you check when you record votes whether they have the cookie?

Jared
Mar 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mark | last post by:
I am designing a game for a forum. When the user has finished playing I need to save their data to a cookie then navigate to a page which holds their score data (I can't have both sets of data on...
8
by: Andrew Phillipo | last post by:
I have a layout which works perfectly. It is three column, the central column is width:auto; with margins and the columns are absolutely positioned at top:0px; left:0px; and top:0px;right:0px; ...
3
by: Jeroen Ceuppens | last post by:
I need a selection tracker on a graphic Idea: left click: rectangle appear en grows when you move the mouse, again clicking is lock te rectangle How do you do that? Greetz Jeroen
1
by: Daniel Michaeloff | last post by:
Hi all, I have an application that when finished redirects to a non-ASP.NET app which is choking on a huge ASP.NET session cookie. The cookie "ASP.NET_SessionId" gets transmitted by the browser...
158
by: Giovanni Bajo | last post by:
Hello, I just read this mail by Brett Cannon: http://mail.python.org/pipermail/python-dev/2006-October/069139.html where the "PSF infrastracture committee", after weeks of evaluation, recommends...
11
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the...
4
by: Nanker | last post by:
In our .NET 1.1 ASP.NET application, I'm noticing some behavior that I would like to change. If I open a web browser and manually copy and paste a URL, then I get a new session ID (I check it by...
7
by: monomaniac21 | last post by:
hi i have a php site which allows users to save a cookie on their computer which stores their user id details and allows them to auto- login. i'm wondering whether this is safe, is it...
3
by: MangroveRoot | last post by:
Hi all ... I've been learning and using PHP for a couple months now, working on a couple of somewhat different sites. On one site, I have a page with a form, and that form includes a couple of...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.