char.inc
上传用户:luoweizhao
上传日期:2021-11-29
资源大小:15269k
文件大小:7k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. <%
  2. 'html字符转换过滤,完全模式
  3. function htmlencode(str)
  4. dim result
  5. dim l
  6. if isNULL(str) then 
  7. htmlencode=""
  8. exit function
  9. end if
  10. l=len(str)
  11. result=""
  12. dim i
  13. for i = 1 to l
  14. select case mid(str,i,1)
  15. case "<"
  16. result=result+"&lt;"
  17. case ">"
  18. result=result+"&gt;"
  19. case chr(13)
  20. result=result+"<br>"
  21. case chr(34)
  22. result=result+"&quot;"
  23. case "&"
  24. result=result+"&amp;"
  25. case chr(32)
  26. 'result=result+"&nbsp;"
  27. if i+1<=l and i-1>0 then
  28. if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9)  then                       
  29. result=result+"&nbsp;"
  30. else
  31. result=result+" "
  32. end if
  33. else
  34. result=result+"&nbsp;"
  35. end if
  36. case chr(9)
  37. result=result+"    "
  38. case else
  39. result=result+mid(str,i,1)
  40. end select
  41. next 
  42. htmlencode=result
  43. end function
  44. 'html字符转换过滤,模式1
  45. function htmlencode1(fString)
  46. if fString<>"" and not isnull(fString) then
  47. fString = replace(fString, "&gt;", ">")
  48. fString = replace(fString, "&lt;", "<")
  49. fString = Replace(fString, "&nbsp;", chr(32))
  50. fString = Replace(fString, "</P><P>", CHR(10) & CHR(10))
  51. fString = Replace(fString, "<BR>", CHR(10))
  52. htmlencode1=fString
  53. else
  54. htmlencode1=""
  55. end if
  56. end function
  57. 'html字符转换过滤,模式2
  58. function htmlencode2(fString)
  59. if fString<>"" and not isnull(fString) then
  60. fString = Replace(fString, chr(32), "&nbsp;")
  61. fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
  62. fString = Replace(fString, CHR(10), "<BR>")
  63. htmlencode2=fString
  64. else
  65. htmlencode2=""
  66. end if
  67. end function
  68. 'html字符转换过滤,模式3
  69. function htmlencode3(fString)
  70. if fString<>"" and not isnull(fString) then
  71. fString = replace(fString, "&gt;", ">")
  72. fString = replace(fString, "&lt;", "<")
  73. htmlencode3=fString
  74. else
  75. htmlencode3=""
  76. end if
  77. end function
  78. 'html字符转换过滤,模式4,不能过滤<>,因为文章标题有字体效果
  79. function htmlencode4(fString)
  80. if fString<>"" and not isnull(fString) then
  81. fString = replace(fString, "<br>", "")
  82. htmlencode4=fString
  83. else
  84. htmlencode4=""
  85. end if
  86. end function
  87. '函数
  88. function sustainhtml(str)
  89.     dim result
  90.     dim l
  91.     if isNULL(str) then 
  92.        sustainhtml=""
  93.        exit function
  94.     end if
  95.     l=len(str)
  96.     result=""
  97. dim i
  98. for i = 1 to l
  99.     select case mid(str,i,1)
  100.            case chr(13)
  101.                 result=result+"<br>"
  102.            case chr(34)
  103.                 result=result+"&quot;"
  104.                    case chr(32)            
  105.                 'result=result+"&nbsp;"
  106.                 if i+1<=l and i-1>0 then
  107.                    if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9)  then                       
  108.                       result=result+"&nbsp;"
  109.                    else
  110.                       result=result+" "
  111.                    end if
  112.                 else
  113.                    result=result+"&nbsp;"                     
  114.                 end if
  115.            case "&"
  116.                 result=result+"&amp;"
  117.            case chr(9)
  118.                 result=result+"    "
  119.            case else
  120.                 result=result+mid(str,i,1)
  121.          end select
  122.        next 
  123.        sustainhtml=result
  124.    end function
  125. '检查sql字符串中是否有单引号,有则进行转化,支持部分HTML的时候采用,过滤危险js代码
  126.    function CheckStr(str)
  127.         dim tstr,l,i,ch
  128.     l=len(str)
  129.     for i=1 to l
  130.         ch=mid(str,i,1)
  131.         if ch="'" then
  132.         tstr=tstr+"'"
  133.      end if
  134.         if ch="(" then
  135.         tstr=tstr+"("
  136.      end if
  137.      tstr=tstr+ch
  138.                 if ch="[" then
  139.         tstr=tstr+"["
  140.      end if
  141.                 if ch=" " then
  142.         tstr=tstr+""
  143.      end if
  144.      
  145.      
  146.     next
  147.     CheckStr=tstr
  148.    end function
  149. '检查email合法性
  150. function IsValidEmail(email)
  151. dim names, name, i, c
  152. 'Check for valid syntax in an email address.
  153. IsValidEmail = true
  154. names = Split(email, "@")
  155. if UBound(names) <> 1 then
  156.    IsValidEmail = false
  157.    exit function
  158. end if
  159. for each name in names
  160.    if Len(name) <= 0 then
  161.      IsValidEmail = false
  162.      exit function
  163.    end if
  164.    for i = 1 to Len(name)
  165.      c = Lcase(Mid(name, i, 1))
  166.      if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
  167.        IsValidEmail = false
  168.        exit function
  169.      end if
  170.    next
  171.    if Left(name, 1) = "." or Right(name, 1) = "." then
  172.       IsValidEmail = false
  173.       exit function
  174.    end if
  175. next
  176. if InStr(names(1), ".") <= 0 then
  177.    IsValidEmail = false
  178.    exit function
  179. end if
  180. i = Len(names(1)) - InStrRev(names(1), ".")
  181. if i <> 2 and i <> 3 then
  182.    IsValidEmail = false
  183.    exit function
  184. end if
  185. if InStr(email, "..") > 0 then
  186.    IsValidEmail = false
  187. end if
  188. end function
  189. 'SQL注入过滤
  190. '--- 传入参数 ---
  191. 'ParaName:参数名称-字符型
  192. 'ParaType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符)
  193.  Public Function ChkRequest(ParaName,ParaType)
  194. Dim ParaValue
  195. If ParaType=1 then
  196. ParaValue=ParaName
  197.  If Not (ParaValue="") then
  198. If not isNumeric(ParaValue)  then
  199. ParaValue=""
  200. Show_Err("参数" & ParaName & "必须为数字型!")
  201. Response.end
  202. End if
  203. End if
  204. Else
  205. If IsNull(ParaValue) Then
  206. ParaValue = ""
  207. Else
  208. ParaValue = Trim(ParaName)
  209. ParaValue = Replace(ParaValue,"'","''")
  210. End if
  211. End if
  212. ChkRequest=ParaValue
  213. End function
  214. function Show_Err(str)%>
  215. <html>
  216. <head>
  217. <meta http-equiv="Content-Language" content="zh-cn">
  218. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  219. <LINK href=site.css rel=stylesheet>
  220. <title><%=copyright%><%=version%>&nbsp;<%=ver%></title>
  221. </head>
  222. <body topmargin="0">
  223. <table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#FFDFBF" width="100%" id="AutoNumber1">
  224. <tr> 
  225. <td width="100%" height="5" >&nbsp;</td>
  226. </tr>
  227. <tr> 
  228. <td width="100%" height="100" align="center"><font face="楷体_GB2312" size="5" color=red><b><%if str="" then%>对不起,你没有执行该操作的权限!<%else%><%=str%><%end if%></td></font>
  229. </td>
  230. </tr>
  231. <tr> 
  232. <td width="100%" height="25" align="center">如发现程序中存在问题,请及时和我们联系</td>
  233. </tr>
  234. </table>
  235. </body>
  236. </html>
  237. <%
  238. end function
  239. function Show_Message(str)%>
  240. <html>
  241. <head>
  242. <meta http-equiv="Content-Language" content="zh-cn">
  243. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  244. <LINK href=site.css rel=stylesheet>
  245. <title><%=copyright%><%=version%>&nbsp;<%=ver%></title>
  246. </head>
  247. <body topmargin="0">
  248. <table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#FFDFBF" width="100%" id="AutoNumber1">
  249. <tr> 
  250. <td width="100%" height="5" >&nbsp;</td>
  251. </tr>
  252. <tr> 
  253. <td width="100%" height="100" align="center"><font face="楷体_GB2312" size="5" color=red><b><%if str="" then%>对不起,你没有执行该操作的权限!<%else%><%=str%><%end if%></td></font>
  254. </td>
  255. </tr>
  256. <tr> 
  257. <td width="100%" height="25" align="center">如发现程序中存在问题,请及时和我们联系</td>
  258. </tr>
  259. </table>
  260. </body>
  261. </html>
  262. <%end function%>