flow79
asked on
Preventing multiple votes in Poll
Hello all! I have a quick and easy poll setup in ASP. It works like a charm, but I would like to be able to block a user from voting more than once. How would I modify my code to do so?
<body>
<form method="post" action="poll.asp">
What is the best web development resource?
<table summary="" class="poll">
<tr>
<td><input type="radio" name="poll" value="Spoono"></td>
<td>Spoono</td>
</tr>
<tr>
<td><input type="radio" name="poll" value="EE"></td>
<td>Experts Exchange</td>
</tr>
<tr>
<td><input type="radio" name="poll" value="Google"></td>
<td>Google</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" class="submit"></td>
</tr>
</table>
</form>
<table style="width: 250px;">
<tr>
<td>
Results:
<%
Dim oConnA
Dim DRIVER
Dim SQLA
Dim poll
Set oConnA=Server.CreateObject ("ADODB.Co nnection")
oConnA.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=c:\Inetpub\wwwroot\db 1.mdb;"
poll = Request.Form("poll")
if poll = "" or IsNull(poll) then
else
SQLA="insert into Poll(results, count) Values ('" & poll & "', 1)"
oConnA.execute(SQLA)
end if
%>
<%
Dim MXID
Dim MXIDER
SQLE="select Max([Ref ID]) AS MXID from Poll"
set inTableC = oConnA.execute(SQLE)
MXIDER = inTableC("MXID")
%>
<br><br>
<%
Dim inTableB
Dim responseone
responseone = "Spoono"
SQLB="select Sum(count) from Poll WHERE results = '"&responseone&"' "
inTableB = oConnA.execute(SQLB)
for each xfield in inTableB
percentage1 = (xfield.value / MXIDER) * 100
percentage1a = left(percentage1, 2)
response.write "<table><tr><td class=""left"">" & xfield.value & " ("& percentage1a &"%)</td><td width="& percentage1 * 2 & " class=""graph""></td></tr> </table>"
next
%>
<%
Dim inTableC
Dim yfield
Dim responsetwo
responsetwo = "EE"
SQLC="select Sum(count) from Poll WHERE results = '"&responsetwo&"' "
inTableC = oConnA.execute(SQLC)
for each yfield in inTableC
percentage2 = (yfield.value / MXIDER) * 100
percentage2a = left(percentage2, 2)
response.write "<table><tr><td class=""left"">" & yfield.value & " (" & percentage2a & "%)</td><td width=" & percentage2 * 2 & " class=""graph""></td></tr> </table>"
next
%>
<%
Dim inTableD
Dim zfield
Dim responsethree
responsethree = "Google"
SQLD="select Sum(count) from Poll WHERE results = '"&responsethree&"' "
inTableD = oConnA.execute(SQLD)
for each zfield in inTableD
percentage3 = (zfield.value / MXIDER) * 100
percentage3a = left(percentage3, 2)
response.write "<table><tr><td class=""left"">" & zfield.value & " (" & percentage3a & "%)</td>"
response.write "<td width=" & percentage3 * 2 & " class=""graph""></td></tr> </table>"
next
%>
<%
response.write "<b>Total Votes:</b> " & MXIDER & ""
%><br><br>
<div style="font-size: 7pt; text-align: center;">This poll is not scientific - multiple votes are allowed per person</div>
</td>
</tr>
</table>
</body>
<body>
<form method="post" action="poll.asp">
What is the best web development resource?
<table summary="" class="poll">
<tr>
<td><input type="radio" name="poll" value="Spoono"></td>
<td>Spoono</td>
</tr>
<tr>
<td><input type="radio" name="poll" value="EE"></td>
<td>Experts Exchange</td>
</tr>
<tr>
<td><input type="radio" name="poll" value="Google"></td>
<td>Google</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" class="submit"></td>
</tr>
</table>
</form>
<table style="width: 250px;">
<tr>
<td>
Results:
<%
Dim oConnA
Dim DRIVER
Dim SQLA
Dim poll
Set oConnA=Server.CreateObject
oConnA.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=c:\Inetpub\wwwroot\db
poll = Request.Form("poll")
if poll = "" or IsNull(poll) then
else
SQLA="insert into Poll(results, count) Values ('" & poll & "', 1)"
oConnA.execute(SQLA)
end if
%>
<%
Dim MXID
Dim MXIDER
SQLE="select Max([Ref ID]) AS MXID from Poll"
set inTableC = oConnA.execute(SQLE)
MXIDER = inTableC("MXID")
%>
<br><br>
<%
Dim inTableB
Dim responseone
responseone = "Spoono"
SQLB="select Sum(count) from Poll WHERE results = '"&responseone&"' "
inTableB = oConnA.execute(SQLB)
for each xfield in inTableB
percentage1 = (xfield.value / MXIDER) * 100
percentage1a = left(percentage1, 2)
response.write "<table><tr><td class=""left"">" & xfield.value & " ("& percentage1a &"%)</td><td width="& percentage1 * 2 & " class=""graph""></td></tr>
next
%>
<%
Dim inTableC
Dim yfield
Dim responsetwo
responsetwo = "EE"
SQLC="select Sum(count) from Poll WHERE results = '"&responsetwo&"' "
inTableC = oConnA.execute(SQLC)
for each yfield in inTableC
percentage2 = (yfield.value / MXIDER) * 100
percentage2a = left(percentage2, 2)
response.write "<table><tr><td class=""left"">" & yfield.value & " (" & percentage2a & "%)</td><td width=" & percentage2 * 2 & " class=""graph""></td></tr>
next
%>
<%
Dim inTableD
Dim zfield
Dim responsethree
responsethree = "Google"
SQLD="select Sum(count) from Poll WHERE results = '"&responsethree&"' "
inTableD = oConnA.execute(SQLD)
for each zfield in inTableD
percentage3 = (zfield.value / MXIDER) * 100
percentage3a = left(percentage3, 2)
response.write "<table><tr><td class=""left"">" & zfield.value & " (" & percentage3a & "%)</td>"
response.write "<td width=" & percentage3 * 2 & " class=""graph""></td></tr>
next
%>
<%
response.write "<b>Total Votes:</b> " & MXIDER & ""
%><br><br>
<div style="font-size: 7pt; text-align: center;">This poll is not scientific - multiple votes are allowed per person</div>
</td>
</tr>
</table>
</body>
There is no real way to stop that. You could try placing a cookie when the user votes and then not allow duplicates, but saavy users can get around that and some users don't allow cookies at all.
FtB
FtB
As an alternative to 1 per IP, you could also insert a combination of IP address & time stamp (say minute or hour), so that the same IP address could be used but only once per hour or minute.
Kinda difficult to be full proof. You would need to store the IP Address (HTTP_REFERER) in the poll table with the vote. Then compare the IP Address in table to new vote IP Address, and if in the table, disallow vote.
But, this would prevent voting from within the same businesses. Many businesses have multiple users in a domain, but on one external IP address.
But, this would prevent voting from within the same businesses. Many businesses have multiple users in a domain, but on one external IP address.
ASKER
can you show me how to actually implement it in the code?
I dont really mind about the multiple users at the same company (its not internal) - just a nice bonus feature a user can set up on a blog site.
I dont really mind about the multiple users at the same company (its not internal) - just a nice bonus feature a user can set up on a blog site.
ASKER
or fritz - how do i set up the cookie? any help using the code i already have would be great!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My posts was only 2 minutes later, and it took a while to type. I am aware of the policies, thanks.
ASKER
thats seems to produce errors:
it opened fine the first time - but when i tested it (selected an option and submitted), it shot back with the error:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/test/poll.asp, line 73
line 73 is: set inTableC = oConnA.execute(SQLE)
it opened fine the first time - but when i tested it (selected an option and submitted), it shot back with the error:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/test/poll.asp, line 73
line 73 is: set inTableC = oConnA.execute(SQLE)
ASKER
actually, i think i got it - i had to remove the connection string from within the if-then - but it still does stop the voting. Thanks Fritz!
Glad to have helped,
FtB
FtB
I recommend millsofts answer. When using cookies, the user controls cookies and all they have to do is erase the cookies. If you store IP, then it's under your control. If the person really wants to vote again, then cookies will not stop them.
Just a thought...
Just a thought...
ASKER
alorentz - i understand that issue - but this poll is just an added feature users can add to their blogging pages. It does not need to be scientific (it is not so important that if someone turned off cookies, it would be a big deal). But if I ever do need to make a poll completely scientific (by truly only allowing 1 vote per IP), i will use that method.
@alorentz--
I already mentioned that above:
https://www.experts-exchange.com/questions/21082091/Preventing-multiple-votes-in-Poll.html#11716669. The problem, as others have already pointed out, that many users may share the same IP if they work for the same company, have the same ISP and etc.
Fritz the Blank
I already mentioned that above:
https://www.experts-exchange.com/questions/21082091/Preventing-multiple-votes-in-Poll.html#11716669. The problem, as others have already pointed out, that many users may share the same IP if they work for the same company, have the same ISP and etc.
Fritz the Blank
@golfDoctor--
Fair enough. If you like, I am happy to delete the comment.
Fritz the Blank
Page Editor
ASP Topic Area
Fair enough. If you like, I am happy to delete the comment.
Fritz the Blank
Page Editor
ASP Topic Area
2. Create a unique index on the IP address field.
3. Catch resulting insert errors from duplicates.
Quick and dirty, but it will prevent multiple people at the same IP address from participating. Note however, that may not be what you want. Different users in the same company often have the same IP address when appearing at an external website (due to Network Address Translation at their firewall).
But, if it suits your purpose it's very easy to implement.
Brad