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. -
%@ Language=VBScript %>
-
<%
-
Option Explicit ' Never code without it!
-
Response.Buffer = True ' Make sure we can redirect later
-
-
' The constants I use in this script...
-
' pulled directly from adovbs.inc
-
Const adOpenForwardOnly = 0
-
Const adOpenDynamic = 2
-
Const adLockReadOnly = 1
-
Const adLockPessimistic = 2
-
Const adCmdText = &H0001
-
-
' This needs to be ' for SQL Server and # for Access
-
Const DATE_DELIMITER = "#"
-
-
Dim strName ' Friendlyname of the redirect
-
Dim strId ' id the redirect
-
Dim cnnLinkTracker ' ADO objects
-
Dim rsLinkTracker
-
Dim strSQL ' SQL command building area
-
Dim iRedirectId ' id of the redirect for logging process
-
-
' Get name of location to go to
-
' I simply call this name so to call the script it would look
-
' something like this:
-
' http://server/linktracker.asp?id=asp101
-
' where asp101 is the friendly id from the database
-
strId = Request.QueryString("id")
-
-
' Make it DB friendly just in case a ' got in somehow
-
strId = Replace(strId, "'", "''")
-
-
' Create a new connection
-
Set cnnLinkTracker = Server.CreateObject("ADODB.Connection")
-
-
' Your connection string goes here!
-
' This one expects an Access database in the same place as this script
-
cnnLinkTracker.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
-
Server.MapPath("/xxxxxxxxxxxx"), "", ""
-
-
' Create a recordset
-
Set rsLinkTracker = Server.CreateObject("ADODB.Recordset")
-
-
' Get the record we're looking for by passing it the name
-
' we got from the QueryString. I'm prebuilding the SQL command
-
' to make it easier to debug if we need to.
-
strSQL = "SELECT PostCard, Headline FROM tblGreet " & _
-
"WHERE PostCardID=" & strId & ";"
-
' Quick and dirty debugging when something goes wrong.
-
'Response.Write strSQL
-
-
' Send the command to the database to get the appropriate records
-
rsLinkTracker.Open strSQL, cnnLinkTracker, _
-
adOpenForwardOnly, adLockReadOnly, adCmdText
-
-
' If we got back any results then we know where to send them
-
' o/w I just send them to our home page for lack of a better
-
' place to send them.
-
If Not rsLinkTracker.EOF Then
-
' Get redirect Id # from recordset
-
iRedirectId = rsLinkTracker.Fields("PostCard").Value
-
-
' Get location to send the user to
-
strName = rsLinkTracker.Fields("Headline").Value
-
-
' We've got all the info we need so close our recordset
-
rsLinkTracker.Close
-
-
' I now recycle the recordset for the logging process.
-
' Lots of people would argue with me about this, but I
-
' know I'm doing it and this is my code so if you don't
-
' like it feel free to change it, but I'm not going to!
-
-
' Start logging process
-
-
' Build out SQL String ahead of time.
-
' This should get us the record containing the information
-
' for the selected link for today's date if one exists.
-
strSQL = "SELECT link_id, hit_date, hit_count " & _
-
"FROM tblLinkTrackerLog " & _
-
"WHERE link_id = " & iRedirectId & " " & _
-
"AND hit_date = " & DATE_DELIMITER & Date() & DATE_DELIMITER
-
-
' Standard debugging step when something goes wrong!
-
'Response.Write strSQL
-
-
' Send the command.
-
rsLinkTracker.Open strSQL, cnnLinkTracker, _
-
adOpenDynamic, adLockPessimistic, adCmdText
-
-
' If it's EOF then it's the first hit of the day and we need
-
' to add a new record o/w we simply update the existing hit
-
' count of the record by adding one to it.
-
If rsLinkTracker.EOF Then
-
rsLinkTracker.AddNew
-
-
rsLinkTracker.Fields("link_id").Value = iRedirectId
-
rsLinkTracker.Fields("hit_date").Value = Date()
-
rsLinkTracker.Fields("hit_count").Value = 1
-
Else
-
rsLinkTracker.Fields("hit_count").Value = _
-
rsLinkTracker.Fields("hit_count").Value + 1
-
End If
-
-
' Save changes to the data
-
rsLinkTracker.Update
-
Else
-
' If no match send em to our home page
-
strName = "/"
-
End If
-
-
' Close our recordset object
-
rsLinkTracker.Close
-
Set rsLinkTracker = Nothing
-
-
' Kill our connection
-
cnnLinkTracker.Close
-
Set cnnLinkTracker = Nothing
-
-
' Send them on their merry way using the location we got
-
' from the database!
-
Response.Redirect "http://" & strName
-
%>
Thanks
Richard
2 1610
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 - ' Send the command.
-
rsLinkTracker.Open strSQL, cnnLinkTracker, _
-
adOpenDynamic, adLockPessimistic, adCmdText
-
-
'Establish cookie for unique hit Counting
-
-
Response.Cookies("Visited").Expires=date+1
-
strVisited = Request.Cookies("Visited")
-
-
' If it's EOF then it's the first hit of the day and we need
-
' to add a new record o/w we simply update the existing hit
-
' count of the record by adding one to it.
-
-
If rsLinkTracker.EOF Then
-
rsLinkTracker.AddNew
-
-
rsLinkTracker.Fields("link_id").Value = iRedirectId
-
rsLinkTracker.Fields("hit_date").Value = Date()
-
rsLinkTracker.Fields("hit_count").Value = 1
-
-
Response.Cookies("Visited") = "yes"
-
' Save changes to the data
-
rsLinkTracker.Update
-
Else
-
If strVisited = "" Then
-
Response.Cookies("Visited") = "yes"
-
'Increment the visitor counter number by 1
-
rsLinkTracker.Fields("hit_count").Value + 1
-
' Save changes to the data
-
rsLinkTracker.Update
-
End If
-
End If
How do you check when you record votes whether they have the cookie?
Jared
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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;
...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |