51代码网ORACLEMYSQLSQL SERVER其它数据库java/jspasp/asp.netC/C++/VC++APP应用其它语言服务器应用
您现在的位置: 51代码网 >> asp.net >> 文章正文

如何限制一个IP地址每天投票次数

更新时间:2012-5-3:  来源:51代码网

简单说下限制投票。
建立一个IP日志表,用来记录IP地址的。
有用户投票时,记录下IP地址,搜索当天时间该IP投票次数。
如果当天次数小于10,就可以投票。投票完成后就把对应该IP的次数加1。
如果当天次数大于等于10,就不让投票了。


Public 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 = Checkstr(Trim(Mid(strIPAddr, 1, 30)))
End Function
Public Function Checkstr(Str)
   If Isnull(Str) Then
    CheckStr = ""
    Exit Function
   End If
   Str = Replace(Str,Chr(0),"")
   CheckStr = Replace(Str,"'","''")
End Function
Dim count
count = conn.Execute("select count(*) from vote where IP='" & GetIP() & "' and [Date]='" & date() & "'")(0)
If count > 10 Then
   Response.Write "不能投票"
   Response.End
Else
   ' 执行投票
   ' 对IP进行记录
   If count = 0 Then
      conn.Execute("insert into vote(IP,[Date]....) value(...)")
   Else
      conn.Execute("update vote_from set .... where IP='' and [date]=...")
   End If
End If

  • 上一篇文章:
  • 下一篇文章: 没有了
  • 赞助商链接
    推荐文章
  • 此栏目下没有推荐文章
  • {
    设为首页 | 加入收藏 | 友情链接 | 网站地图 | 联系站长 |