45IT.COM- 电脑学习从此开始!
DIY硬件教程攒机经验装机配置
设计Photoshop网页设计特效
系统注册表DOS系统命令其它
存储主板显卡外设键鼠内存
维修显卡CPU内存打印机
WinXPVistaWin7unix/linux
CPU光驱电源/散热显示器其它
修技主板硬盘键鼠显示器光驱
办公ExcelWordPowerPointWPS
编程数据库CSS脚本PHP
网络局域网QQ服务器
软件网络系统图像安全
页面导航: 首页 > 设计学院 > 网络编程 > ASP教程 >

asp对非法字符进行过滤的代码

电脑软硬件应用网 45IT.COM 时间:2012-03-08 23:30 作者:逸风

asp对非法字符进行过滤

'此文件可以对整站提交文字进行过滤
'函数说明:对非法字符进行过滤
'这个函数将过滤所有非中文字符
function ClearString(str)
   dim re,str1,str2,i
   set re = new regexp re.Pattern = "^[\u4e00-\u9fa5\s\n\r\t]+$"
   for i=1 to len(str)
     str1 = mid(str,i,1)
     clearString = re.Test(str1)
     if clearString=true then
     str2 = str2&str1
     end if
   next
   str=str2
   ClearString = str
end function
function KillKey(str)
    KillKey=str
end function
'编写者:逸风
'编写日期:2008-6-4
'函数说明:对非法字符进行过滤
'这个函数将过滤所有非中文字符

function SearchKey(str)
Key="这里是非法字符 嘎嘎`~~CSDN也屏蔽的"
KeyArray=split(Key,",")
K=ubound(KeyArray)
str2=ClearString(str)
for i=0 to K
    if Instr(str2,KeyArray(i)) then
        response.Write("<font color=red>您所提交的信息中包含非法字符,请您返回后仔细检查所填写的内容然后再次提交您的信息!</font><a href='javascript:history.go(-1);'>返回</a><br/><font color=#0000FF>感谢您的支持!</font><br/>非法字符:" & KeyArray(i))
        response.End()
    end if
next
SearchKey=str
end function
function urldecode(encodestr)   'encodestr就是要解码的字符串
Dim newstr,havechar,lastchar,i,char_c,next_1_c,next_1_Num
newstr=""
havechar=false
lastchar=""
for i=1 to len(encodestr)
   char_c=mid(encodestr,i,1)
   if char_c="+" then
    newstr=newstr & " "
   elseif char_c="%" then
    next_1_c=mid(encodestr,i+1,2)
    next_1_num=cint("&H" & next_1_c)
  
    if havechar then
     havechar=false
     newstr=newstr & chr(cint("&H" & lastchar & next_1_c))
    else
     if abs(next_1_num)<=127 then
      newstr=newstr & chr(next_1_num)
     else
      havechar=true
      lastchar=next_1_c
     end if
    end if
    i=i+2
   else
    newstr=newstr & char_c
   end if
next
urldecode=newstr
end function

 


TempStr1=urldecode(request.QueryString)
TempStr2=urldecode(request.Form)
'查询提交的信息 如有非法字符 直接终止程序运行
SearchKey(TempStr1)
SearchKey(TempStr2)

 

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
无法在这个位置找到: baidushare.htm
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码:点击我更换图片
推荐知识