<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.saas.query.baseQueryConf.JDBCExceute" %>
<%!
public String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
public String getCookieIPAddress(HttpServletRequest request,HttpServletResponse response,String ip_address) {
Cookie[] cookies = request.getCookies();
String cookievalue ="";
if(null!=cookies && cookies.length!=0) {
for(int i=0;i<cookies.length;i++) {
Cookie cookie = cookies[i];
if(cookie.getName().equals("cookie_ip_"+ip_address)) {
String value= cookie.getValue();
String[] value_array=value.split("\\|");
int time= Integer.parseInt(value_array[1])+1;
cookievalue = value_array[0]+"|"+time;//取出原来cookie中的信息,在后面追加信息
Cookie c = new Cookie("cookie_ip_"+ip_address,cookievalue); //编码后添加都cookie
c.setMaxAge(60 * 60);
c.setPath("/");
response.addCookie(c);
}
else {
Cookie c = new Cookie("cookie_ip_"+ip_address,ip_address+"|1");
c.setMaxAge(24*60*60);
c.setPath("/");
response.addCookie(c);
}
System.out.println(cookievalue);
}
}
return cookievalue;
}
%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String article_id = request.getParameter("article_id")!=null ? request.getParameter("article_id").toString() : "";
String ip_address = getIpAddr(request);
String vote_stats="";
String cookie_ip = getCookieIPAddress(request,response,ip_address);
String[] cookie_ip_array = cookie_ip.split("\\|");
System.out.println(cookie_ip_array[1]);
if(!"".equals(cookie_ip_array[1].toString().trim()) && Integer.parseInt(cookie_ip_array[1])>=20) {
vote_stats="每个IP地址每天限投20票";
}
else {
JDBCExceute jdbc = new JDBCExceute();
jdbc.CRUD("update ith_article set rsrv_str4=rsrv_str4+1 where article_id='"+article_id+"'");
vote_stats="投票成功";
}
%>
<%=vote_stats%>
分享到:
相关推荐
js控制 cookie访问限制ip,有些兼容性问题,需要自行修改,
ASP.NET——ASP.NET利用Cookie处理网上重复投票ASP.NET——ASP.NET利用Cookie处理网上重复投票ASP.NET——ASP.NET利用Cookie处理网上重复投票
cookie servlet jsp 登录 记录登陆次数
ASP.NET中Cookie对象的使用,利用Cookie对象防止重复投票代码,在代码中还有倒计时的代码,都是拿来就可以用的
使用动态IP池+cookie爬取豆瓣豆瓣影评数据
if(!IsPostBack) { UserInfo userInfo = Session["userInfo"] as UserInfo; if (userInfo == null) { Response.Redirect("Login.aspx");... Response.Write("登录次数为:" + count + " "); }
用jsp中的cookie实现记录用户名,密码,还有第几次登录的信息
自动投票C#源代码,能够保持cookie链接
cookie购物车cookie购物车cookie购物车cookie购物车cookie购物车cookie购物车cookie购物车cookie购物车cookie购物车cookie购物车cookie购物车cookie购物车
cookie cookie cookie cookie cookie cookie cookie cookie cookie cookie cookie cookie cookie cookie
主要介绍了Java 模拟cookie登陆简单操作,结合实例形式分析了Java 模拟cookie登陆的相关原理与基本实现技巧,需要的朋友可以参考下
如何创建 cookie? setcookie() 函数用于设置 cookie。 注释:setcookie() 函数必须位于 <html> 标签之前。 创建您的第一个PHP cookie 当您创建一个cookie,使用函数setcookie,你必须指定三个参数。这些参数...
用VS 2005做的网上投票系统
$.cookie('the_cookie'); // 获得cookie $.cookie('the_cookie', 'the_value'); // 设置cookie $.cookie('the_cookie', 'the_value', { expires: 7 }); //设置带时间的cookie $.cookie('the_cookie', '', { expires:...
cookie的一些操作函数的封装,如:添加、删除、获取cookie中key对应的Value值、判断cookie是否存在
C#操作cookie,解密加密cookie
最近做了一个项目,其中有项目需求是,要用cookie实现限制点赞次数,特此整理,把实现代码分享给大家供大家学习
本篇文章是对使用cookie实现统计访问者登陆次数的代码进行了详细的分析介绍,需要的朋友参考下
用了1年多的软件了,挺不错的,免费的,共享下!
FlashCookie 不被浏览器清除的Cookie 不被浏览器清空的Cookie