Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • Last Modified:

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.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
flow79
Asked:
flow79
  • 5
  • 5
  • 2
  • +2
1 Solution
 
millsoftCommented:
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
 
fritz_the_blankCommented:
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
 
millsoftCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
golfDoctorCommented:
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
 
flow79Author Commented:
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
 
flow79Author Commented:
or fritz - how do i set up the cookie?  any help using the code i already have would be great!
0
 
fritz_the_blankCommented:
<%
%>


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
 
golfDoctorCommented:
My posts was only 2 minutes later, and it took a while to type.  I am aware of the policies, thanks.
0
 
flow79Author Commented:
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
 
flow79Author Commented:
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
 
fritz_the_blankCommented:
Glad to have helped,

FtB
0
 
alorentzCommented:
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
 
flow79Author Commented:
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
 
fritz_the_blankCommented:
@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
 
fritz_the_blankCommented:
@golfDoctor--

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

Fritz the Blank
Page Editor
ASP Topic Area
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now