网络编程
位置:首页>> 网络编程>> Asp编程>> 3个比较好用的asp检查函数

3个比较好用的asp检查函数

作者:AloneSword 来源:csdn 发布时间:2007-09-24 13:25:00 

标签:检查,函数

因为比较简单,我就不说什么了。一看就明白的!

1.sql防注入函数



Function ChkStr(InString) 
  If InString<>"" Then 
   InString=Replace(LCase(InString)," ","") 
   InString=Replace(LCase(InString),";","") 
   InString=Replace(LCase(InString),"’","") 
   InString=Replace(LCase(Instring),"--","") 
   Instring=Replace(LCase(Instring),"%","") 
   InString=Replace(LCase(InString),"%20","") 
   
   InString=Replace(LCase(InString),"admin","") 
   
   InString=Replace(LCase(InString),"and","") 
   InString=Replace(LCase(InString),"or","") 
   
   InString=Replace(LCase(InString),"asc","") 
   InString=Replace(LCase(Instring),"chr","") 
   InString=Replace(LCase(InString),"mid","") 
   InString=Replace(LCase(InString),"len","") 
   
   InString=Replace(LCase(InString),"select","") 
   InString=Replace(LCase(InString),"insert","") 
   InString=Replace(LCase(InString),"delete","") 
   InString=Replace(LCase(InString),"update","") 
   
   
   ChkStr=InString 
  End If 
  End Function 


2.检查文件是否合法,在 AccessExt="gif,jpg,jpeg,bmp,doc,txt,png"  定义允许的文件类型


Function CheckFileExt(FileExt) 
   Dim FileAccessExt,AccessExt 
   AccessExt="gif,jpg,jpeg,bmp,doc,txt,png" 
   FileAccessExt=Split(AccessExt,",") 
   For i=LBound(FileAccessExt) to UBound(FileAccessExt) 
   If LCase(FileExt)=LCase(FileAccessExt(i)) Then 
   CheckFileExt=True 
   Else 
   CheckFileExt=False 
   End If 
   Next 
  End Function

 


3.检查字符串是否数字

Function CheckStr(str,IsStr) 
  CheckStr=str 
  If IsStr And InStr(str,",")>0 Then 
   Call errmsg("提交字符中包含非法字符") 
  ElseIf (Not IsStr) And (Not IsNumeric(str)) Then 
   Call errmsg("提交不是数字型") 
  End If 
  End Function 
   
  Sub errmsg(str) 
   If Not IsNull(str) Then 
   Response.Write(str)&"< br >" 
   Call ASCpy() 
   Response.End() ’Very Improtan.Stop execute program. 
   End If 
  End Sub 



小结:
  
  最值得学习的还是response.End()的合理使用,非常的好。只要出现错误马上终止程序的运行,不给后面的机会,保证数据的安全。

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com