首页 » ASP代码 » 一个简单的投票系统源码

一个简单的投票系统源码

功能有防止外部提交,限制提交时间,限制单用户投票总次数,限制对某个人投票次数。以下是完整的代码。
详见内页:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
on error resume next
Set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("istoupiao2009data.mdb")
Response.Expires = 0
Response.Expiresabsolute = Now() - 1 
Response.AddHeader "pragma","no-cache" 
Response.AddHeader "cache-control","private" 
Response.CacheControl = "no-cache"
userid = cint(request("userid"))
localip = getIP()
if err.number<>0 or userid=0 then ShowMsg("操作失败,请重试。")
 
 
repeatTime = 120	'重复投票时间(分钟)  - 这三个参数如为 0 表示无限制
SingleVote = 5		'对单个人投票次数限制(次)  - 
PublicVote = 10		'对所有人投票次数限制(次)
 
 
 
'判断来源地址
if CheckUrl=false then ShowMsg("禁止外部提交")
 
'统计该用户总共投了多少个票
if PublicVote>0 then
sql = "select count(ipaddr) from voteinfo WHERE ipaddr='" & localip & "'"
set pubrs = conn.execute(sql)
if pubrs(0) >= PublicVote then ShowMsg("您的总投票已经超过限制数,不能再投票了。")
end if
'if pubrs(0) >50 then '加入限制   'sql = "insert into lockip(ipaddr) values('" & localip & "')"  'conn.execute(sql)
 
'判定该用户上次最后投票时间,如果间隔小于2小时则停止
sql = "select top 1 votetime,ipaddr from voteinfo WHERE ipaddr='" & localip & "' ORDER BY votetime desc"
set timers = conn.execute(sql)
if isdate(timers(0)) and repeatTime>0 then
	if datediff("n",timers(0),now())  <= repeatTime then ShowMsg("您投票速度太快,请过一会再来。" ) 
end if
 
'统计该用户对单个人投票次数
if SingleVote>0 then
sql = "select count(foruser) from voteinfo WHERE ipaddr='" & localip & "' and foruser=" & userid
set sinrs=conn.execute(sql)
if sinrs(0) >= SingleVote then ShowMsg("您对本选手的投票次数超过限制。")
end if
 
 
'保存该次投票,反馈信息
sql = "insert into voteinfo(ipaddr,foruser) values('" & localip & "'," & userid & ")"
conn.execute(sql)
ShowMsg("投票成功,感谢!")
 
 
 
Function CheckUrl()
	checkurl=true
	server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
	server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
	if mid(server_v1,8,len(server_v2)) <> server_v2 then checkurl=false
End Function
 
Sub ShowMsg(str)
	on error resume next
	conn.close
	set pubrs=nothing
	set timers=nothing
	set sinrs=nothing
	set conn=nothing
	err.clear
	response.Redirect ("message.asp?str=" & str)
	response.End()
End Sub
 
Function getIP() 
  Dim strIPAddr 
  If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then 
    strIPAddr = Request.ServerVariables("REMOTE_ADDR") 
  ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then 
    strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1) 
  ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then 
    strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1) 
  Else 
    strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR") 
  End If
  getIP = Trim(Mid(strIPAddr, 1, 30)) 
End Function
%>

,

转发到新浪微博 转发到新浪微博

目前这篇文章有4条评论(Rss)

  1. If you are patient in one moment of anger you will escape a hundred days of sorrow.

  2. cheap | #2
    05/16/2012 at 13:42

    h4kRM6 I appreciate you sharing this blog.Really thank you! Want more.

  3. Nike zoom soldier | #3
    05/16/2012 at 21:30

    I LOVE THE WEBSITE VERY MUCH. IT HELP ME LEARN A LOTS OF USEFUL KNOWLEGE. HOPE THE HOST WOULD PROVIDE MORE AND MORE.TKS.

  4. Carroll B. Merriman | #4
    05/17/2012 at 03:04

    Finally found a customer service page please close my account i dont recive refunds when i return merchandise i gave these packages to the postman i dont have a tracking no.one item was the evil eye pendant and the other was the fake lv bag which seller claimed to be authentic i am not comfortable with ebay sellers i continue to get ripped off i would rather pay full price than purchase from ebay close immediatley i feel ebay is hoorible.

我要评论