彻底屏蔽鼠标右键
oncontextmenu="window.event.returnvalue=false"将彻底屏蔽鼠标右键 或者 <script language="javascript"> function click() { if (event.button==0) //event.button依环境值不同 { alert("对不起,本页的内容不经允许不得拷备。"); } } window.document.onmousedown=click; </script>
onpaste="returnfalse"不准粘贴
oncopy="returnfalse;"oncut="returnfalse;"防止复制
光标是停在文本框文字的最后
functioncc() { vare=event.srcElement; varr=e.createTextRange(); r.moveStart(’character’,e.value.length); r.collapse(true); r.select(); }
判断上一页的来源
asp:request.servervariables("HTTP_REFERER") javascript:document.referrer
网页不会被缓存
Response.Expires=-1 Response.ExpiresAbsolute=Now()-1 Response.cachecontrol="no-cache"
过滤HTML标签后的内容 ’函数名:RemoveHTML ’作 用:清除HTML标签 ’参 数:strHTML 内容 ’返回值:过滤HTML标签后的内容
function RemoveHTML(strHTML) Dim objRegExp, Match, Matches Set objRegExp = New Regexp objRegExp.IgnoreCase = True objRegExp.Global = True ’取闭合的<> objRegExp.Pattern = "<.+?>" ’进行匹配 Set Matches = objRegExp.Execute(strHTML) ’遍历匹配集合,并替换掉匹配的项目 For Each Match in Matches strHtml=Replace(strHTML,Match.Value,"") Next RemoveHTML=strHTML Set objRegExp = Nothing End function
Function IIF(Expression,ReturnTrue,ReturnFalse) If Expression Then IIF = ReturnTrue Else IIF = ReturnFalse End If End Function
全功能安全过滤函数
’参数:请求方式,过滤类型,请求名,值类型,默认值 Function SafeRequest(Requester,FilterType,RequestName,RequestType,DefaultValue) Dim tmpValue Select Case Requester Case 0 : tmpValue = RequestName Case 1 : tmpValue = Request(RequestName) Case 2 : tmpValue = Request.Form(RequestName) Case 3 : tmpValue = Request.QueryString(RequestName) Case 4 : tmpValue = Request.Cookies(RequestName) End Select
Select Case RequestType Case 0 If Not IsNumeric(tmpValue) Or Len(tmpValue) <=0 Then tmpValue = CLng(DefaultValue) Else tmpValue = CLng(tmpValue) End If Case 1 If tmpValue="" Or IsNull(tmpValue) Then tmpValue=DefaultValue Select Case FilterType Case 0 : tmpValue = tmpValue Case 1 : tmpValue = SafeSql(tmpValue) Case 2 : tmpValue = FilterHtml(tmpValue) End Select Case 2 If Not IsDate(tmpValue) Or Len(tmpValue) <=0 Then tmpValue = CDate(DefaultValue) Else tmpValue = CDate(tmpValue) End If End Select
SafeRequest = tmpValue End Function
危险Sql过滤
’参数:Sql ’返回:过滤结果 Function SafeSql(str) SafeSql = Replace(str, "’", "'") End Function ’函数:过滤Html标签 ’参数:字符串 ’返回:过滤后的字符串 Function FilterHtml(str) If IsNull(str) Or str="" Then FilterHtml="" : Exit Function Dim r Set r = New RegExp r.IgnoreCase = True r.Global = True r.MultiLine = True
r.Pattern = " <.+?>" FilterHtml = r.Replace(str,"") Set r = Nothing End Function
判断发言是否来自外部
’ChkPost=false 来自外部提交(非法) ’ChkPost=true 合法提交表单
function ChkPost() dim server_v1,server_v2 chkpost=false server_v1=LCase(Cstr(Request.ServerVariables("HTTP_REFERER"))) server_v2=LCase(Cstr(Request.ServerVariables("SERVER_NAME"))) if mid(server_v1,8,len(server_v2)) <>server_v2 then chkpost=false else chkpost=true end if end function
ASP身份证号码验证函数
//var sss = "422324860305482"; //Response.Write(checkIDCard(sss, "03/05/1986", 0));
function checkIDCard(s, d, g) { if (!s) return false; d = new Date(d); if (!d.getTime()) return false;
var t, r;
t = "" + d.getFullYear() + dblNum(d.getMonth() + 1) + dblNum(d.getDate());
if (g == null || isNaN(g)) return false; g = parseInt(g) % 2;
switch (s.length) { case 8 : if (new Date() > d.setFullYear(d.getFullYear() + 19)) return false; r = /^[\d]{8}$/; if (!r.test(s)) return false; if (s != t) return false;
break; case 15 : r = /^[\d]{15}$/; if (!r.test(s)) return false; if (s.substr(6, 6) != t.substr(2)) return false; if (parseInt(s.charAt(14)) % 2 != g) return false;
break; case 18 : r = /^(?:[\d]{18}|[\d]{17}X)$/i; if (!r.test(s)) return false; if (s.substr(6, 8) != t) return false; if (parseInt(s.charAt(16)) % 2 != g) return false;
var n = 0; var w = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); // 加权因子 var c = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"); // 校验码
for (var i = 0; i < 17; i++) { n += parseInt(s.charAt(i)) * w[i]; }
if (s.charAt(17).toUpperCase() != c[n % 11]) return false;
break; default : return false; }
return true; }
function dblNum(n) { return parseInt(n) < 10 ? "0" + n : n; } 本文来自 13COM.NET, 本文地址:http://www.13com.net/article/article.asp?articleid=49
|