友情链接防刷PV测试代码
没做验证..貌似正确...先记录一下
1
private 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
else19

{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
else29

{30
if (idList.IndexOf(aid) < 0) //第一次点击31

{32
idList.Add(aid);33
timeList.Add(DateTime.Now);34
count.UrlStat(aid, true); //进来的PV统计35
}36
else37

{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
}

浙公网安备 33010602011771号