473,662 Members | 2,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

link tracker with cookie to stop repeat clicking

229 New Member
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 1627
fran7
229 New Member
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 Recognized Expert Specialist
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
2100
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 the same page because I can't control the forum design). The score data is updated with the results held in the cookie and the cookie is deleted. I need to stop the user just typing for example javascript:document.cookie="myScore=1000000" into the...
8
2264
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; In the right column I have a javascript link which hides the column. This is very necessary due to the width of content shown on the site at times. Clicking the link makes the scrollbars appear for no aparent reason - both horizontal by about...
3
2907
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
9255
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 (IE6 in test case) despite trying Microsoft's suggested method of expiring the cookie first. I'd like to be able to kill the cookie and do a Response.Redirect() from within a server-side button handler, but I'm to the point now where I'm...
158
6361
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 using a non open source tracker (called JIRA - never heard before of course) for Python itself. Does this smell "Bitkeeper fiasco" to anyone else than me? --
11
11522
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 function whether i click the link then i tried this (using forms)
4
3329
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 entering javascript:document.cookie in the URL field to get the cookies for the page). However, if I instead click on the same URL in an email link, the browser that is opened will reuse the session ID if another browser is already open to the...
7
4266
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 possible for a malicious user to find that cookie and change its value and therefore auto-login as someone else? and if so how can this be prevented?
3
2036
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 ACTION=SUBMIT buttons, so that clicking either button will immediately reload the page only with an argument tacked on, e.g. "?size=128" or "?size=256". This causes some images to be resized, but otherwise the page appears the same.
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.