日期:2014-05-18  浏览次数:21212 次

设计一个投票系统,能够防止重复投票(使用cookie)
如何用多种方法实现

------解决方案--------------------
cookie能有效防止重复投票吗?我清除cookie再投票不就行了?还有,用户禁用cookie怎么办?
------解决方案--------------------
你都知道用Cookie实现了,那就动手写呗
建议使用jquery的cookie来实现,代码更少,都封装好了

移入jquery.js和jquery.cookie.js后

C# code

共<span id="voteNum">0</span>票
<input type="button" id="btnVote" value="投票"/>

$(function(){
     $("#btnVote").click(function(){
           if($.cookie("vote")!=null){
               alert("已经投过票,请无重复投票,谢谢!");
               return;
           }else{
              $("#voteNum").text(parseInt($("#voteNum").text())+1); //票数加1
              alert("谢谢投票!");
              //写cookie到客户端
              $.cookie("vote","XXX", {expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true});
           }
     });
});

------解决方案--------------------
将IP记录数据库,,,,,,,,,, 读取数据库进行判读。。
------解决方案--------------------
最好只能做到,检测IP,并记录。
同时检查是否使用代理,若使用代理,拒绝投票,就可以了,cookie也用上,不过那个太容易绕过去了,

下面代码做代理检测的
public static bool checkIpPro()
{
bool bl = false;
string FY_IP = string.Empty;
FY_IP = HttpContext.Current.Request.ServerVariables["ALL_HTTP"].ToLower();
if (FY_IP.IndexOf("proxy") > 0 || FY_IP.IndexOf("http_via") > 0 || FY_IP.IndexOf("http_pragma") > 0 || 
!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_PROXY_CONNECTION"])||
!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_VIA"]) || 
!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT_VIA"]) ||
!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] )|| 
!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_PROXY_CONNECTION"] ) ||

!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_CACHE_INFO"])
)
{
bl = true;
}
return bl;
}
------解决方案--------------------
要放入数据库啊。用cookies?禁用了cookies或清除了cookies咋办?