Solved

Preventing multiple votes in Poll

Posted on 2004-08-04
16
572 Views
Last Modified: 2008-03-10
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.Connection")
oConnA.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=c:\Inetpub\wwwroot\db1.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>
0
Comment
Question by:flow79
  • 5
  • 5
  • 2
  • +2
16 Comments
 
LVL 5

Expert Comment

by:millsoft
ID: 11716663
1. Add IP address to your POLL table, & insert that value into the POLL table also (IP can be found in the request object I believe).
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
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11716669
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
0
 
LVL 5

Expert Comment

by:millsoft
ID: 11716671
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.  
0
 
LVL 16

Expert Comment

by:golfDoctor
ID: 11716684
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.
0
 
LVL 13

Author Comment

by:flow79
ID: 11716686
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.
0
 
LVL 13

Author Comment

by:flow79
ID: 11716694
or fritz - how do i set up the cookie?  any help using the code i already have would be great!
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 500 total points
ID: 11716906
<%
%>


Results:
<%
Dim oConnA
Dim DRIVER
Dim SQLA
Dim poll
if request.cookies("bolCastVote") = "" then
  Response.Cookies("bolCastVote")="True"
  Response.Cookies("firstname").Expires=#May 10,2020#
  Set oConnA=Server.CreateObject("ADODB.Connection")
  oConnA.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=c:\Inetpub\wwwroot\db1.mdb;"
  poll = Request.Form("poll")
  if poll = "" or IsNull(poll) then
  else
   SQLA="insert into Poll(results, count) Values ('" & poll & "', 1)"
   oConnA.execute(SQLA)
else
response.write("You have already voted!")
end if
%>
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 16

Expert Comment

by:golfDoctor
ID: 11716959
My posts was only 2 minutes later, and it took a while to type.  I am aware of the policies, thanks.
0
 
LVL 13

Author Comment

by:flow79
ID: 11716971
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)
0
 
LVL 13

Author Comment

by:flow79
ID: 11716987
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!
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11716995
Glad to have helped,

FtB
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11717027
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...
0
 
LVL 13

Author Comment

by:flow79
ID: 11717062
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.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11717406
@alorentz--

I already mentioned that above:

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21082091.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
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11718985
@golfDoctor--

Fair enough. If you like, I am happy to delete the comment.

Fritz the Blank
Page Editor
ASP Topic Area
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now