Salve a tutti,
andando alla ricerca di un sondaggio con voto unico, senza registrazione, ho trovato uno script che registra l'ip nel db ed impedisce un secondo voto... finché non si ha un nuovo ip
A questo punto vorrei integrare un scrittura/controllo cookies, ma non so come fare e dove mettere le mani.
Come fare?
codice:
<%
'Two varibles are passed into the db
'u_input is the value if the user entered a response to
'the vote/poll question....IP is the address of the user
u_input=request.form("u_input")
u_ip=request.servervariables("remote_addr")
' if the user did not enter anything in the poll on this visit
' then display the poll question and possible choices
if u_input = "" then
%>
<form method="post" action="<%= request.servervariables("script_name") %>">
Quali basi inedite vuoi contribuire a realizzare?
<input type="radio" value="1" name="u_input">A
<input type="radio" value="2" name="u_input">B
<input type="radio" value="3" name="u_input">C
<input type="radio" value="4" name="u_input">D
<input type="radio" value="5" name="u_input">E
<input type="radio" value="6" name="u_input">F
<input type="radio" value="7" name="u_input">G
<input type="radio" value="8" name="u_input">H
<input type="submit" value="Vota" ></p>
</form>
<%
else
' if the user did input a choice on the vote/ballot
' check to see if their ip address is already in the db
accessdb="votes_db"
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath("/mdb-database/votes_db.mdb")
set rs = server.createobject("ADODB.Recordset")
sql = "select ip from ballot where ip ='" & u_ip & "'"
rs.Open sql, cn
if rs.eof then
' if the user has not voted previously indicate it
been_here_before="No"
end if
rs.close
if been_here_before = "No" then
' Since the user has not voted previously their input
' their vote will be added to the db
sql = "insert into ballot (ip, selection" & u_input &") "
sql = sql & "values ('" & u_ip & "',1)"
rs.Open sql, cn
end if
'This will summerize and count the records in the db
sql= "select distinctrow sum(selection1) as sum_selection1, "
sql= sql & "sum(selection2) AS sum_selection2, sum(selection3) AS sum_selection3, "
sql= sql & "sum(selection4) AS sum_selection4, sum(selection5) AS sum_selection5, "
sql= sql & "sum(selection6) AS sum_selection6, sum(selection7) AS sum_selection7, "
sql= sql & "sum(selection4) AS sum_selection8, count(*) AS total_votes "
sql= sql & "FROM ballot;"
rs.Open sql, cn
total1=rs ("sum_selection1")
total2=rs ("sum_selection2")
total3=rs ("sum_selection3")
total4=rs ("sum_selection4")
total5=rs ("sum_selection5")
total6=rs ("sum_selection6")
total7=rs ("sum_selection7")
total8=rs ("sum_selection8")
count=rs ("total_votes")
%>
A[img]images/red.jpg[/img]">
<%= formatnumber((total1/count)*100,1) %>%
B[img]images/yellow.jpg[/img]">
<%= formatnumber((total2/count)*100,1) %>%
C[img]images/green.jpg[/img]">
<%= formatnumber((total3/count)*100,1) %>%
D[img]images/blue.jpg[/img]">
<%= formatnumber((total4/count)*100,1) %>%
E[img]images/blue.jpg[/img]">
<%= formatnumber((total5/count)*100,1) %>%
F[img]images/blue.jpg[/img]">
<%= formatnumber((total6/count)*100,1) %>%
G[img]images/blue.jpg[/img]">
<%= formatnumber((total7/count)*100,1) %>%
H[img]images/blue.jpg[/img]">
<%= formatnumber((total8/count)*100,1) %>%
Total Votes: <%= formatnumber(count,0,0) %>
<% if been_here_before <> "No" then %>
Hai già votato, questo voto non è stato conteggiato
<% else %>
Voto valido
<% end if %>
<% end if %>