友情链接防刷PV测试代码
没做验证..貌似正确...先记录一下
Code
1private static List<string> idList = new List<string>();
2 private static List<DateTime> timeList = new List<DateTime>();
3 protected void Page_Load(object sender, EventArgs e)
4 {
5 if (!IsPostBack)
6 {
7 AntiSQLInjection sqli = new AntiSQLInjection();
8 string aid = sqli.ReplaceStr(Request.QueryString["aid"]);
9 GetNavigationUrl count = new GetNavigationUrl();
10 if ((idList == null || idList.Count == 0) && (timeList == null || timeList.Count == 0))
11 {
12 idList = new List<string>();
13 timeList = new List<DateTime>();
14 idList.Add(aid);
15 timeList.Add(DateTime.Now);
16 count.UrlStat(aid, true); //进来的PV统计
17 }
18 else
19 {
20 if (idList.Count != timeList.Count)
21 {
22 idList = new List<string>();
23 timeList = new List<DateTime>();
24 idList.Add(aid);
25 timeList.Add(DateTime.Now);
26 count.UrlStat(aid, true); //进来的PV统计
27 }
28 else
29 {
30 if (idList.IndexOf(aid) < 0) //第一次点击
31 {
32 idList.Add(aid);
33 timeList.Add(DateTime.Now);
34 count.UrlStat(aid, true); //进来的PV统计
35 }
36 else
37 {
38 int index = idList.IndexOf(aid);
39 DateTime oldTime = timeList[index];
40 if (oldTime.AddMinutes(1) <= DateTime.Now) //超时
41 {
42 timeList[index] = DateTime.Now;
43 count.UrlStat(aid, true); //进来的PV统计
44 } //1分钟内不算进统计
45 }
46 }
47 }
48 Response.Redirect("XXX");
49 }
50 }
51 }
1private static List<string> idList = new List<string>();
2 private static List<DateTime> timeList = new List<DateTime>();
3 protected void Page_Load(object sender, EventArgs e)
4 {
5 if (!IsPostBack)
6 {
7 AntiSQLInjection sqli = new AntiSQLInjection();
8 string aid = sqli.ReplaceStr(Request.QueryString["aid"]);
9 GetNavigationUrl count = new GetNavigationUrl();
10 if ((idList == null || idList.Count == 0) && (timeList == null || timeList.Count == 0))
11 {
12 idList = new List<string>();
13 timeList = new List<DateTime>();
14 idList.Add(aid);
15 timeList.Add(DateTime.Now);
16 count.UrlStat(aid, true); //进来的PV统计
17 }
18 else
19 {
20 if (idList.Count != timeList.Count)
21 {
22 idList = new List<string>();
23 timeList = new List<DateTime>();
24 idList.Add(aid);
25 timeList.Add(DateTime.Now);
26 count.UrlStat(aid, true); //进来的PV统计
27 }
28 else
29 {
30 if (idList.IndexOf(aid) < 0) //第一次点击
31 {
32 idList.Add(aid);
33 timeList.Add(DateTime.Now);
34 count.UrlStat(aid, true); //进来的PV统计
35 }
36 else
37 {
38 int index = idList.IndexOf(aid);
39 DateTime oldTime = timeList[index];
40 if (oldTime.AddMinutes(1) <= DateTime.Now) //超时
41 {
42 timeList[index] = DateTime.Now;
43 count.UrlStat(aid, true); //进来的PV统计
44 } //1分钟内不算进统计
45 }
46 }
47 }
48 Response.Redirect("XXX");
49 }
50 }
51 }