以下是我使用asp过程中经常用到的一些函数,贴出来大家分享一下:
1、页面跳转函数
function MsgBox(str,stype,url) ?response.write "<script language="javascript">" ?response.write "alert('"&str&"');" ?select case stype ? case "Back" ?? response.write "history.go(-1);" ? case "GoUrl" ?? response.write "window.location='"&url&"'" ? case "Close" ?? response.write "window.close()" ?end select ?response.write "</script> " End function
2、用于接收地址栏参数传递时SQL组合保护,修改自oblog程序
Function Protectrequest(sSql) ?If ISNull(sSql) Then Exit Function ?sSql=Trim(sSql) ?If sSql="" Then Exit Function ?sSql=Replace(sSql,Chr(0),"") ?sSql=Replace(sSql,"'","") ?sSql=Replace(sSql,"%","") ?sSql=Replace(sSql,"-","") ?sSql=Replace(sSql,">","") ?sSql=Replace(sSql,"<","") ?sSql=Replace(sSql,"&","") ?sSql=Replace(sSql,";","") ?sSql=Replace(sSql,"+","") ?sSql=Replace(sSql,"[","") ?sSql=Replace(sSql,"[","") ?sSql=Replace(sSql,"{","") ?sSql=Replace(sSql,"}","") ?sSql=Replace(sSql,"(","") ?sSql=Replace(sSql,")","") ?sSql=Replace(sSql,"""","") ?Protectrequest=sSql End Function
3、检查数字安全
function checknum(numid) dim blnReturn ???? dim i ???? blnReturn=True ???? for i=1 to len(numid) ?????? if not isnumeric(mid(numid,i,1)) then ?????????? blnReturn=False ?????????? exit for ?????? end if ???? next if len(numid)<1 then blnReturn=False if blnReturn=False then msgbox "数据格式不正确!","GoUrl","index.asp" response.End() end if end function
4、检查文件是否存在
function checkfileexits(filepathname) ??? If IsObjInstalled("Scripting.FileSystemObject") = False Then ? Response.Write "此功能要求服务器支持文件系统对象(FSO),而你当前的服务器不支持!" ?End If ? ??? Set oFSO = Server.CreateObject("Scripting.FileSystemObject") ? ?? if filepathname="" or isnull(filepathname) then ? checkfileexits=false ?? else ? sMapFileName = Server.MapPath(filepathname) ? If? oFSO.FileExists(sMapFileName) Then ?? checkfileexits=filepathname ? else ?? checkfileexits=false ? End If ?end if ?Set oFSO = Nothing ?checkfileexits=checkfileexits end function
5、截取字符串
function fetchcodes(strcodes,fetcnum) if len(strcodes)>fetcnum then strcodes=left(strcodes,fetcnum)&"..." else strcodes=strcodes end if fetchcodes=strcodes end function
6、检查已安装组件
Function IsObjInstalled(strClassString) ?On Error Resume Next ?IsObjInstalled = False ?Err = 0 ?Dim xTestObj ?Set xTestObj = Server.CreateObject(strClassString) ?If 0 = Err Then IsObjInstalled = True ?Set xTestObj = Nothing ?Err = 0 End Function
7、判断访问页面来源,禁止直接输入地址访问
sub ComeUrl() dim ComeUrl,cUrl ComeUrl=lcase(trim(request.ServerVariables("HTTP_REFERER"))) if ComeUrl="" then ?? msgbox"对不起,无法直接输入页面地址浏览!","Back","" ?? response.end() else ?cUrl=trim("http://" & Request.ServerVariables("SERVER_NAME")) ?if mid(ComeUrl,len(cUrl)+1,1)=":" then ? cUrl=cUrl & ":" & Request.ServerVariables("SERVER_PORT") ?end if ?cUrl=lcase(cUrl & request.ServerVariables("SCRIPT_NAME")) ?if lcase(left(ComeUrl,instrrev(ComeUrl,"/")))<>lcase(left(cUrl,instrrev(cUrl,"/"))) then ? msgbox"对不起,无法通过外部链接浏览!","Back","" ? response.end ?end if end if end sub
8、取得ip地址
function getip() getip=Request.ServerVariables("HTTP_X_FORWARDED_FOR") If? getip= ""? then getip=Request.ServerVariables("REMOTE_ADDR") end if end function
先贴这8个吧,有好的再贴出来!
发表评论
相关文章
国内AI资源汇总,AI聊天、AI绘画、AI写作、AI视频、AI设计、AI编程、AI音乐等,国内顺畅访问,无需科学上网。
扫码或点击进入:萤火AI大全
文章分类
最新评论