您的位置:寻梦网首页编程乐园ASP编程>ASP常用代码
ASP世界
ASP常用代码
作者:佚名  转自:http://www.dezai.cn/


---------------清除所有SESSION信息----------------------
Session.Abandon()

---------------获取真实IP地址---------------------------

userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then
userip = Request.ServerVariables("REMOTE_ADDR")
End if

-----------------启用FSO-----------------------------

regsvr32 scrrun.dll '这个东西害惨我了。。。。

-------------------返回上一页-----------------------

request.servervariables("HTTP_REFERER")

--------------限制输入汉字 英文和标点,只能数字------------------

<td><strong>手机:</strong></td>
<td width="63%"><input name="Phone" id="Phone" size="30" maxlength="12" onkeyup="value=value.replace(/[^\w&=]|_/ig,'')"
onkeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" />
<font color="#FF0000">*</font></td>

解释:
size="30" maxlength="12" 这个SIZE是输入框的长度,maxlength="12"是说显示只能输入12个字符
onkeyup="value=value.replace(/[^\w&=]|_/ig,'')" '限制不能输入汉字和符号
onkeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" /> '限制只能输入数字
<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"> '只能输入汉字
<input onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"> '只能输入英文和数字

--------------计算字段总和------------------

select sum(id) from table where ……

Response.Write ""&Rs(0)&""

--------------提取时间------------------

Year(Date())&Month(date())&Day(date())&Hour(Now())&Minute(Now())&Second(Now())


记录以往写的ASP- 常用函数
2007年04月26日 星期四 00:40 A.M.

<%

sub nocache()
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
end sub


dim StartTime
StartTime=Timer()
Function GetTimeOver()
if Timer()>=StartTime    then
if Timer() - StartTime >1 then
     getTimeOver = FormatNumber(Timer() - StartTime, 5, true)& "秒"
    Else
     getTimeOver = FormatNumber((Timer() - StartTime) * 1000, 3, true)& "毫秒"
End If
Else
if Timer()+86400-StartTime>1 then
     getTimeOver = FormatNumber(Timer()+86400-StartTime, 5, true)& "秒"
    Else
     getTimeOver = FormatNumber((Timer()+86400-StartTime) * 1000, 3, true)& "毫秒"
End If
end If
End Function

sub echo(str)
response.write str
End sub

sub echoCookies(Key,Value,Expires)
    DomainPath=Left(Request.ServerVariables("script_name"),inStrRev(Request.ServerVariables("script_name"),"/"))
    Response.Cookies(Key)=""&Value&""
    if Expires<>0 then Response.Cookies(Key).Expires=date+Expires
    Response.Cookies(Key).Path=DomainPath
End sub

sub CleanCookies()
    DomainPath=Left(Request.ServerVariables("script_name"),inStrRev(Request.ServerVariables("script_name"),"/"))
    For Each objCookie In Request.Cookies
     Response.Cookies(objCookie)= ""
     Response.Cookies(objCookie).Path=DomainPath
    Next
End sub

sub Alert(msg,goUrl)
    msg = replace(msg,"'","\'")
If goUrl="" Then
       goUrl="history.go(-1);"
    Else
     goUrl="window.location.href='"&goUrl&"'"
End IF
    Response.Write ("<script language=""JavaScript"" type=""text/javascript"">"&vbNewLine&"alert('" & msg & "');"&goUrl&vbNewLine&"</script>")
End sub

Function GetIP()
Dim Temp
Temp = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If Temp = "" or isnull(Temp) or isEmpty(Temp) Then Temp = Request.ServerVariables("REMOTE_ADDR")
    If Instr(Temp,"'")>0 Then Temp="0.0.0.0"
GetIP = Temp
End Function

nocache
for k=0 TO 100000
getTimeOver()
next
echo GetTimeOver()
echo "<br>"
echo GetIP
%>