我想做一个限制ip的投票程序~
但是下面的代码只是限制cookie~
我的思路是将投过票的ip 存入一个数据库中~ 然后每次投票的时候再查询~ 如果有记录 则退出~
所以 求各位高手~ 最好把下面这个核心代码修改一下~
Function getIP()
getIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If getIP = "" Then getIP = (Request.ServerVariables("REMOTE_ADDR"))
End Function
if Request.Cookies("mycookie")("userip")<>"" then
Response.Write "<script>alert('一个IP地址只能投一次票,谢谢您的参与!');history.go(-1);</script>"
response.End()
else
Response.Cookies("mycookie")("userip")=getIP()
Response.Cookies("mycookie").Expires=date+30
end if
if
********************************************************************************************
=============================================================================================
用ip来判断很容易作弊,可以用代理服务器来刷票。
新建一个表voteip 存放 投票题目vid,投票时间date,投票人IP地址ip
数据库连接就省略了。
vid=request("id")'当前投票题目的id,肯定是以参数形式传来的
set Rs=Server.CreateObject("Adodb.Recordset")
Ip=getIP()
if ip="" then
response.write("<script>alert('ip获取错误,请不要使用代理,或隐藏ip');history.go(-1);</script>")
response.end()
end if
Rs.open "select * from userip where ip='"&Ip&"'" and vid="&vid&" and datediff(d,[date],getdate)>0",conn,1,3 '如不需要记录时间 把时间判断去掉,需要的话自己设置时间间隔。
if not Rs.eof then
Response.Write "<script>alert('一个IP地址一天内只能投一次票,谢谢您的参与!');history.go(-1);</script>"
Response.End()
else
Rs.addnew
Rs("ip")=Ip
rs("vid")=vid
rs("date")=now()
Rs.update
end if
Rs.close
set Rs=nothing
===========================================================================================
Function getIP()
getIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If getIP = "" Then getIP = (Request.ServerVariables("REMOTE_ADDR"))
End Function
'数据库连接就省略了。
Dim Rs,Ip
set Rs=Server.CreateObject("Adodb.Recordset")
Ip=getIP()
Rs.open "select * from userip where ip='"&Ip&"'",conn,1,3
if not Rs.eof then
Response.Write "<script>alert('一个IP地址只能投一次票,谢谢您的参与!');history.go(-1);</script>"
Response.End()
else
Rs.addnew
Rs("ip")=Ip
Rs.update
end if
Rs.close
set Rs=nothing
==============================================================================================
1.提取字段列表
//<%
Set cn=Server.CreateObject("ADODB.Connection")
cn.Open "Provider=SQLOLEDB;Data Source=localhost;" & _
"Initial Catalog=pubs;User ID=sa;Password="
Set rs=cn.Execute("Select * from authors")
While Not rs.EOF
Response.Write rs("au_fname")
rs.MoveNext
Wend
rs.Close
cn.Close
//%>
2.返回数据集函数
Public Function GetData() As ADODB.Recordset
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn=CreateObject("ADODB.Connection")
cn.Open "Provider=SQLOLEDB;Data Source=localhost;" & _
"Initial Catalog=pubs;User ID=sa;Password="
Set rs=CreateObject("ADODB.Connection")
rs.LockType=adLockBatchOptimistic
rs.CursorLocation=adUseClient
rs.CursorType=adOpenStatic
rs.Open "Select * from authors",cn
Set rs.ActiveConnection=Nothing
cn.Close
Set cn=Nothing
Set GetData=rs
End Function
============================================================================================
首先你的有一个存放投票者IP的数据库,
然后判断一个IP地址投票的时候,另外读取数据库判断getIP是否在数据库中存在,如果有,则Response.Write "<script>alert('一个IP地址只能投一次票,谢谢您的参与!');history.go(-1);</script>"
如果没有就把这个getIP添加到数据库rs.update
Dim RsIp,Ip
set RsIp=Server.CreateObject("Adodb.Recordset")
Ip=getIP()
RsIp.open "select * from ip where getIP='"&getIP&"'",conn,1,3
if not RsIp.eof and RsIp.bof then
Response.Write "<script>alert('请不要重复投票!');history.go(-1);</script>"
Response.End()
else
RsIp.addnew
RsIp("getIP")=getIP
RsIp.update
end if
RsIp.close
set RsIp=nothing
限制ip的投票系统解决办法
3星 · 超过75%的资源 需积分: 10 67 浏览量
2009-12-31
14:04:36
上传
评论
收藏 3KB RAR 举报
alex211314
- 粉丝: 2
- 资源: 21
最新资源
- 基于opencv的dnn模块实现Yolo-Fastest的目标检测python源码+模型+说明(高分项目).zip
- 使用Python调用微信本地ocr服务.zip
- 【精品推荐】人工智能在医疗中的应用.pptx
- 【精品推荐】电子医疗仪器人机接口-(1).ppt
- 【精品推荐】电子医疗仪器人机接口.ppt
- ubuntu镜像ubuntu镜像01
- 基于paddle搭建神经网络实现5种水果识别分类python源码+数据集(高分毕设).zip
- 【精品推荐】电子商务网店类型介绍.ppt
- 基于paddle搭建神经网络实现水果识别分类python源码+数据集(高分项目).zip
- 三菱plc编程口通信学习笔记.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈