日期:2014-05-17  浏览次数:20695 次

ASP各类常用函数收集整理(转载)
查看文章
? ?
ASP各类常用函数收集整理
2006-11-02 13:45

获得指定长度的标题名称

' *----------------------------------------
' * 函数:GetString
' * 描述:获得指定长度的标题名称
' * 参数:所取标题相应调用语句str,显示文字的个数n
' * 返回:以n为显示文字个数的str
' * 作者:醋醋狗
' * 日期:2005/6/5
' *----------------------------------------
Function GetString(str,n)
dim str,n,l,t,ln
ln=n*2
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=ln then
GetString=left(str,i)&"..."
exit for
else
GetString=str&" "
end if
next
response.write GetString
End Function


禁止从外部提交数据
<%
'server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
'server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
'if mid(server_v1,8,len(server_v2))<>server_v2 then
'response.write "<script>alert('您出错了!!!\n禁止从外部提交数据');history.go(-1);</Script>"
'Response.End
'end if
%>

页面不被缓存语句

Sub ExpirePage
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
End Sub
在文件的开头调用
<!--#include file="inc/conn.asp"-->
<%call expirepage()%>
就OK了.
再配合
<SCRIPT language=JavaScript>alert('==返回啦==');
javascript:history.go(-1)</SCRIPT>
更爽!!

获得文件扩展名
' *----------------------------------------
' * 函数:GetExtend
' * 描述:获得文件扩展名
' * 参数:文件全名
' * 返回:文件扩展名
' * 作者:
' * 日期:
' *----------------------------------------

function GetExtend(filename)
dim tmp
if filename<>"" then
tmp=mid(filename,instrrev(filename,".")+1,len(filename)-instrrev(filename,"."))
tmp=LCase(tmp)
if instr(1,tmp,"asp")>0 or instr(1,tmp,"php")>0 or instr(1,tmp,"php3")>0 or instr(1,tmp,"aspx")>0 then
getextend="txt"
else
getextend=tmp
end if
else
getextend=""
end if
end function


检测参数是否有SQL危险字符
' *----------------------------------------
' * 函数:CheckIn
' * 描述:检测参数是否有SQL危险字符
' * 参数:str要检测的数据
' * 返回:FALSE:安全 TRUE:不安全
' * 作者:
' * 日期:
' *----------------------------------------
function CheckIn(str)
if instr(1,str,chr(39))>0 or instr(1,str,chr(34))>0 or instr(1,str,chr(59))>0 then
CheckIn=true
else
CheckIn=false
end if
end function

在客户端显示消息框
' *----------------------------------------
' * 函数:alertm
' * 描述:在客户端显示消息框
' * 参数:message:要显示的信息
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------
Sub alertm(message)
message = replace(message,"'","'")
Response.Write ("<script>alert('" & message & "')</script>")
End Sub

在客户端返回上一页
' *----------------------------------------
' * 函数:GoBack
' * 描述:在客户端返回上一页
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------
Sub GoBack() <