www.gusucode.com > 漂亮的地方旅游景点景观介绍网站源代码 > inc/function.asp

    <%
'获取客户端IP/////////////////////////////////////////////////////////////////////
Function Userip()
Dim GetClientIP
GetClientIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If GetClientIP = "" or isnull(GetClientIP) or isempty(GetClientIP) Then
GetClientIP = Request.ServerVariables("REMOTE_ADDR")
end if
Userip = GetClientIP
End function
'获取记录///////////////////////////////////////////////////////////////////////
function getmc(tab,lm,id,xm)
dim rsmc
set rsmc=conn.execute("select "&xm&",id from "&tab&" where "&lm&"="&id) 
if rsmc.eof then
getmc=""
else
getmc=rsmc(xm)
end if
call recordend(rsmc)
end function
'判断是否安全字符串,在注册登录等特殊字段中使用////////////////////////////////
function issafestr(str)
dim s_badstr, n, i
s_badstr = "'  &<>?%,;:()`~!@#$^*{}[]|+-=" & chr(34) & chr(9) & chr(32)
n = len(s_badstr)
issafestr = true
for i = 1 to n
if instr(str, mid(s_badstr, i, 1)) > 0 then
issafestr = false
exit function
end if
next
end function
'quering参数//////////////////////////////////////////////////////////////////////
function url(it)
dim abc,urlstr
for each abc in request.querystring
if not abc=it then
urlstr=urlstr&abc&"="&request.querystring(abc)&"&"
end if
next
url=request.servervariables("path_info")&"?"&urlstr
end function
'出错返回///////////////////////////////////////////////////////////////////////
sub cc(msg)
response.Write("<script>alert('"&msg&"');history.go(-1)</script>")
response.End()
end sub
'清除html代码/////////////////////////////////////////////////////////////////////
function removehtml(strhtml) 
dim objregexp,match,matches 
set objregexp=new regexp 
objregexp.ignorecase=true 
objregexp.global=true 
objregexp.pattern="<.+?>" 
set matches = objregexp.execute(strhtml) 
for each match in matches 
strhtml=replace(strhtml,match.value,"") 
next 
removehtml=strhtml
set objregexp = nothing 
end function 
'替换危险字符//////////////////////////////////////////////////////////////////////
function get_safestr(str)
get_safestr =replace(trim(str), "‘", "")
end function
sub zhgx(tab,id)
conn.execute("update "&tab&" set lastm=now() where id="&id)
end sub
sub uptab(tab,zd1,val1,zd2,val2)
conn.execute("update "&tab&" set "&zd1&"="&val1&" where "&zd2&"="&val2 )
end sub
'排序规则//////////////////////////////////////////////////////////////////
function order(tab,fid)
dim pxzd,pxgz
pxzd=getmc(tab,"id",fid,"pxzd")
pxgz=getmc(tab,"id",fid,"pxgz")
if pxzd<>"" and pxgz<>"" and fid<>0 then 
order=pxzd&" "&pxgz
else
order="qz desc,id desc"
end if
end function
'文件扩展名////////////////////////////////////////////////////////////////////
function fileExec(fileName)
fileExec=mid(fileName,instr(fileName,".")+1,len(fileName)-instr(fileName,"."))
end function
'提取图片/////////////////////////////////////////////////////////////////////
Function getpic(strng) 
Dim regEx,Match,Matches,values '建立变量。 
Set regEx=New RegExp '建立正则表达式。 
regEx.Pattern="src\=.+?\.(gif|jpg|jpeg|png|bmp)" '设置模式。 
regEx.IgnoreCase=true'设置是否区分字符大小写。 
regEx.Global=True'设置全局可用性。 
Set Matches=regEx.Execute(strng) '执行搜索。 
For Each Match in Matches '遍历匹配集合。 
values=values&Match.Value&"|" 
Next 
getpic=Replace(Replace(Replace(values,"'",""),"""",""),"src=","") 
End Function

'仿百度分页//////////////////////////////////////////////////////////////////////////////
function pagenum(page,pagesum)
dim ks,js,i
if pagesum=0 then 
pagenum=pagenum&"<span class=fonth>暂无记录</a>"
else
if cint(page)>10 then 
ks=page-5
js=page+5 
if ks<1 then 
ks=1 
js=ks+10 
end if 
if js>cint(pagesum) then 
js=pagesum 
ks=js-10 
end if 
else 
if cint(pagesum)>11 then 
ks=1 
js=11 
else 
ks=1 
js=pagesum 
end if 
end if 
if page<>1 then 
pagenum=pagenum&"<a href='"&url("page")&"page=1'>[首页]</a> <a href='"&url("page")&"page="&page-1&"'>[上页]</a> " 
else 
pagenum=pagenum&"[首页] [上页] " 
end if 
for i= ks to js 
if i<10 then 
if cint(i)=cint(page) then 
pagenum=pagenum&"<font color='#FF0000'><strong>"&i&"</strong></font> "
else 
pagenum=pagenum&"<a href='"&url("page")&"page="&i&"'>"&i&"</a> "
end if 
else 
if cint(i)=cint(page) then 
pagenum=pagenum&"<font color='#FF0000'><strong>"&i&"</strong></font> "
else 
pagenum=pagenum&"<a href='"&url("page")&"page="&i&"'>"&i&"</a> "
end if 
end if 
next 
if cint(page)<cint(pagesum) then 
pagenum=pagenum&"<a href='"&url("page")&"page="&page+1&"'>[下页]</a> <a href='"&url("page")&"page="&pagesum&"'>[尾页]</a> "
else 
pagenum=pagenum&"[下页] [尾页] "
end if 
end if 
end function 
'取得记录数//////////////////////////////////////////////////////////////////////////////////
function getnum(tj)
dim rsn
set rsn=conn.execute("select count(id) as tol from "&tj)
getnum=rsn("tol")
call recordend(rsn)
end function
'排序规则//////////////////////////////////////////////////////////////////////////////////
function order(tab,fid)
dim pxzd,pxgz
pxzd=getmc(tab,"id",fid,"pxzd")
pxgz=getmc(tab,"id",fid,"pxgz")
if pxzd<>"" and pxgz<>"" and fid<>0 then 
order=pxzd&" "&pxgz
else
order="qz desc,id desc"
end if
end function
'获取表单值////////////////////////////////////////////////////////////////////////////////
function getform(key,lx,e)
select case lx
case 1
if Trim(Request.Form(key))<>"" then 
if e=0 then 
getform=get_safestr(Trim(Request.Form(key)))
else
getform=get_safestr(unescape(Trim(Request.Form(key))))
end if
else
getform=""
end if
case 2
if Trim(Request.Form(key))<>"" then 
getform=int(Trim(Request.Form(key)))
else
getform=""
end if
case 3
if Trim(Request.Form(key))<>"" then 
getform=clng(Trim(Request.Form(key)))
else
getform=""
end if
end select
end function

'生成随机字符,n为字符的个数//////////////////////////////////////////////////////////////
function MyRandc(n) 
dim thechr,i
thechr = ""
for i=1 to n
dim zNum,zNum2
Randomize
zNum = cint(25*Rnd)
zNum2 = cint(10*Rnd)
if zNum2 mod 2 = 0 then
zNum = zNum + 97
else
zNum = zNum + 65
end if
thechr = thechr&chr(zNum)
next
MyRandc = thechr
end function
%>