ASP常用函数收藏

news/2025/2/23 15:27:41

<%
'*******************************************************************
'取得IP地址
'*******************************************************************
Function Userip()
Dim GetClientIP
'如果客户端用了代理服务器,则应该用ServerVariables("HTTP_X_FORWARDED_FOR")方法
GetClientIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If GetClientIP = "" or isnull(GetClientIP) or isempty(GetClientIP) Then
'如果客户端没用代理,应该用Request.ServerVariables("REMOTE_ADDR")方法
GetClientIP = Request.ServerVariables("REMOTE_ADDR")
end if
Userip = GetClientIP
End function

'*******************************************************************
' 弹出对话框
'*******************************************************************
Sub alert(message)
message = replace(message,"'","\'")
Response.Write ("<script>alert('" & message & "')</script>")
End Sub

'*******************************************************************
' 返回上一页,一般用在判断信息提交是否完全之后
'*******************************************************************
Sub GoBack()
Response.write ("<script>history.go(-1)</script>")
End Sub

'*******************************************************************
' 重定向另外的连接
'*******************************************************************
Sub Go(url)
Response.write ("<script>location.href('" & url & "')</script>")
End Sub

'*******************************************************************
' 指定秒数重定向另外的连接
'*******************************************************************
sub GoPage(url,s)
s=s*1000
Response.Write "<SCRIPT LANGUAGE=JavaScript>"
Response.Write "window.setTimeout("&chr(34)&"window.navigate('"&url&"')"&chr(34)&","&s&")"
Response.Write "</script>"
end sub

'*******************************************************************
' 判断数字是否整形
'*******************************************************************
function isInteger(para)
on error resume next
dim str
dim l,i
if isNUll(para) then
isInteger=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isInteger=false
exit function
end if
l=len(str)
for i=1 to l
if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
isInteger=false
exit function
end if
next
isInteger=true
if err.number<>0 then err.clear
end function

'*******************************************************************
' 获得文件扩展名
'*******************************************************************
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

' *----------------------------------------------------------------------------
' * 函数: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

' *----------------------------------------------------------------------------
' * 函数:HTMLEncode
' * 描述:过滤HTML代码
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLEncode(fString)
if not isnull(fString) then
fString = replace(fString, ">", "&gt;")
fString = replace(fString, "<", "&lt;")

fString = Replace(fString, CHR(32), "&nbsp;")
fString = Replace(fString, CHR(9), "&nbsp;")
fString = Replace(fString, CHR(34), "&quot;")
fString = Replace(fString, CHR(39), "&#39;")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")

HTMLEncode = fString
end if
end function

' *----------------------------------------------------------------------------
' * 函数:HTMLcode
' * 描述:过滤表单字符
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLcode(fString)
if not isnull(fString) then
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(34), "")
fString = Replace(fString, CHR(10), "<BR>")
HTMLcode = fString
end if
end function

' *----------------------------------------------------------------------------
' * 函数:HTMLREM
' * 描述:解决过滤
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLREM(fString)
if not isnull(fString) then
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "")
fString = Replace(fString, CHR(10), "")
fString=ReplaceSpace(fString)
fString=HTMLEncode(fString)
HTMLREM = fString
end if
end function

' *----------------------------------------------------------------------------
' * 函数:ReplaceSpace
' * 描述:替换所有相连空格为单空格
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function ReplaceSpace(content)
content=trim(content)
if content="" then
replacespace=""
else
while not instr(1,content," ")=0
content=Replace(content," "," ")
wend
replacespace=content
end if
end function

rem 将字串处理成sql中语句的一部分之搜索条件

function StrToSql_or(content,field)
content=trim(content)
if content="" then
strtosql_or=""
else
' and
strtosql_or=field & " like '%" & replace(content," ","%' or " & field & " like '%") & "%'"
end if
end function

rem 将字串处理成sql中语句的一部分之搜索日期
function StrToSql_Date(searchdate,field)
searchdate=clng(searchdate)
select case searchdate
case 0
StrToSql_Date=""
case 1
StrToSql_Date=field & " between '" & dateadd("ww",-1,date()) & "' and '" & date() & "'"
case 2
StrToSql_Date=field & " between '" & dateadd("m",-1,date()) & "' and '" & date() & "'"
case 3
StrToSql_Date=field & " between '" & dateadd("q",-1,date()) & "' and '" & date() & "'"
case 4
StrToSql_Date=field & " between '" & dateadd("yyyy",-1,date()) & "' and '" & date() & "'"
end select
end function

function StrToSql_Date2(field)
dim date_Previous,date_next
date_previous=dateadd("d",-(Weekday(date(),2)-1),(date() & " 1:00:00"))
date_next=dateadd("d",(7-Weekday(date(),2)),(date() & " 23:59:59"))
StrToSql_Date2=field & " between '" & date_previous & "' and '" & date_next & "'"
end function

rem 字符截断
function Strfix(content,n)
content=trim(content)
if len(content)>n then
Strfix=left(content,n) & "..."
else
Strfix=content
end if
end function

rem 字符串处理-截断(新闻)
function StrNewfix(content)
content=trim(content)
if len(content)>27 then
strnewfix=left(content,27) & "..."
else
strnewfix=content
end if
end function
%>


http://www.niftyadmin.cn/n/608258.html

相关文章

mybatis-plus basemapper扩展_太火了!MyBatis Plus 为啥这么牛?

来源&#xff1a;http://cnblogs.com/thinkYi/p/13723035.html特色正文组件依赖扩展代码大家有用过MyBatis-Plus&#xff08;简称MP&#xff09;的都知道它是一个 MyBatis 的增强工具&#xff0c;致力于 MyBatis 的基础上只做增强不做改变&#xff0c;为简化开发&#xff0c;提…

office2003 rms 加密功能无效

2009-12-11 周五发现rms加密出现问题.表现为 所有的office2003打开加密文档或者创建加密文档时提示: "出现意外的错误。 请稍后再试或与系统管理员联系""Unexpected error occurred. Please try again later or contact your system administrator” (英文offic…

github在哪里点同意_GitHub 热榜:开发者开源「抢茅台脚本」,火了!

大家好&#xff0c;我是小 G。今天逛 GitHub 的时候&#xff0c;偶然发现一个神奇的脚本&#xff1a;Jd_Seckill。脚本作者是 GitHub ID 为「红头土豆」的用户&#xff0c;其主要作用&#xff0c;是能帮你快速抢购某东上的茅台。总所周知&#xff0c;茅台的出厂价跟市场上零售价…

什么是反射?

①什么是反射?反射提供了封装程序集、模块和类型的对象。您可以使用反射动态地创建类型的实例(见④ )&#xff0c;将类型绑定到现有对象(这个不会)&#xff0c;或从现有对象中获取类型(见②③ )。然后&#xff0c;可以调用类型的方法或访问其字段和属性。最最简单的反射:如下u…

Wpe工作原理和教程-以传奇为列

1.Wpe工作原理和可行性分析 wpe所要改的&#xff0c;不是[游戏里面的数值]&#xff0c;而是[伪造信息封包]。 什么意思咧??就是我们用wpe所要改的&#xff0c;并不是"生命力由100变成10000"之类的东西&#xff0c; 这种东西无法用wpe改&#xff0c; 我们要改的可能…

在VC++中实现同步Internet时间

校时原理&#xff1a;互联网上有很多时间服务器能够提供准确的时间&#xff0c;我们通过连接到这样的服务器来获取时间值。这里向大家介绍一下服务器传来的数据格式先。数据一共四个字节&#xff08;4 Byte&#xff09;&#xff0c;我们可以在接收数据后对它进行“重新组装”&a…

打开闪光灯_代驾小哥深夜被一群野狗逼上山路!打开闪光灯拍照:差点吓哭,竟然误入了……...

“喂&#xff01;警察同志&#xff0c;我迷路了&#xff0c;这里黑漆漆一片太吓人了&#xff01;快来帮帮我&#xff01;”8月17日凌晨&#xff0c;浙江杭州西湖区公安分局留下派出所接到一则求助。对方说自己是个代驾司机&#xff0c;晚上接到到某森林公园的订单&#xff0c;但…

巧用WinRAR+Javascript解决activeX的自动安装问题

先纠正一个观点&#xff0c;所谓自动安装并非强制安装&#xff0c;否则就变成流氓软件了&#xff0c;就算是silverlight,flash这类知名ActiveX&#xff0c;用户也有选择安装或是不安装的权利。 较正统的解决办法是提示用户设置IE权限&#xff0c;然后在object里加入codebaseocx…