文章来源: 视点设计 8see.net
http://blog.8see.net/
rem —表单提示函数 being—————————–
code copy …
function check_submit(str,restr)
if str="" then
response.write "<script>"
response.write "alert("&restr&");"
response.write "history.go(-1)"
response.write "</script>"
response.end
else
check_submit=str
end if
end function
code copy …
function alert_submit(str)
response.write "<script>"
response.write "alert("&str&");"
response.write "location.reload();"
response.write "</script>"
end function
code copy …
function localhost_submit(str,urls)
response.write "<script>"
if str<>"" then
response.write "alert("&str&");"
end if
response.write "location="&urls&";"
response.write "</script>"
end function
rem —生成自定义位随机数 being—————————–
code copy …
function makerndid(byval maxlen)
dim strnewpass
dim whatsnext, upper, lower, intcounter
randomize
for intcounter = 1 to maxlen
whatsnext = int(2 * rnd)
if whatsnext = 0 then
upper = 80
lower = 70
else
upper = 48
lower = 39
end if
strnewpass = strnewpass & chr(int((upper – lower + 1) * rnd + upper))
next
makerndid = strnewpass
end function
rem —生成四位随机数 being—————————–
code copy …
function get_rand()
dim num1
dim rndnum
randomize
do while len(rndnum)<4
num1=cstr(chr((57-48)*rnd+48))
rndnum=rndnum&num1
loop
get_rand=rndnum
end function
rem —判断数据是否整型 being—————————–
code copy …
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
rem —数据库链接函数 being—————————–
code copy …
function openconn
set conn = server.createobject("adodb.connection")
connstr="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(db_login)
conn.open connstr
end function
rem —中文字符转uncode代码函数 being—————————–
code copy …
function urlencoding(vstrin)
strreturn = ""
for i = 1 to len(vstrin)
thischr = mid(vstrin,i,1)
if abs(asc(thischr)) < &hff then
strreturn = strreturn & thischr
else
innercode = asc(thischr)
if innercode < 0 then
innercode = innercode + &h10000
end if
hight8 = (innercode and &hff00)\ &hff
low8 = innercode and &hff
strreturn = strreturn & "%" & hex(hight8) & "%" & hex(low8)
end if
next
urlencoding = strreturn
end function
rem —html过滤函数 being—————————–function htmlout(str)
code copy …
dim result
dim l
if isnull(str) then
htmlout=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "<"
result=result+"<"
case ">"
result=result+">"
case chr(13)
if session("admin_system")="" then
result=result+"<br>"
end if
case chr(34)
result=result+"""
case "&"
result=result+"&"
case chr(32)
result=result+" "
if i+1<=l and i-1>0 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+" "
else
result=result+" "
end if
else
result=result+" "
end if
case chr(9)
result=result+" "
case else
result=result+mid(str,i,1)
end select
next
htmlout=result
end function
rem —textarea显示用—
code copy …
function htmlencode1(fstring)
if fstring<>"" and not isnull(fstring) then
fstring = replace(fstring, ">", ">")
fstring = replace(fstring, "<", "<")
fstring = replace(fstring, " ", chr(32))
fstring = replace(fstring, "</p><p>", chr(10) & chr(10))
fstring = replace(fstring, "<br>", chr(10))
htmlencode1=fstring
else
htmlencode1=""
end if
end function
rem —页面显示用—
code copy …
function htmlencode2(fstring)
if fstring<>"" and not isnull(fstring) then
fstring = replace(fstring, ">", ">")
fstring = replace(fstring, "<", "<")
fstring = replace(fstring, chr(32), " ")
fstring = replace(fstring, chr(10) & chr(10), "</p><p>")
fstring = replace(fstring, chr(10), "<br>")
htmlencode2=fstring
else
htmlencode2=""
end if
end function
rem —取出指定字符串前后的字符串方法—
code copy …
function getstrs(str1,charflag,dflag)
dim tmpstr
if dflag=0 then取左
pos1=instr(str1,charflag)
if pos1<=20 then
tmpstr=left(str1,pos1-1)
else
tmpstr=mid(str1,pos1-20,20)
end if
else 取右
pos1=instr(str1,charflag)+len(charflag)
if len(str1)-pos1<=20 then
tmpstr=right(str1,len(str1)-pos1)
else
tmpstr=mid(str1,pos1+1,20)
end if
end if
getstrs=tmpstr
end function
rem —取出文件名—
code copy …
function getfilename(str)
pos=instr(str,".")
if str<>"" then
str=mid(str,pos,len(str))
end if
getfilename=str
end function
rem —取到浏览器版本转换字符串—
code copy …
function browser()
dim text
text = request.servervariables("http_user_agent")
if instr(text,"msie 5.5")>0 then
browser="ie 5.5"
elseif instr(text,"msie 6.0")>0 then
browser="ie 6.0"
elseif instr(text,"msie 5.01")>0 then
browser="ie 5.01"
elseif instr(text,"msie 5.0")>0 then
browser="ie 5.00"
elseif instr(text,"msie 4.0")>0 then
browser="ie 4.01"
else
browser="未知"
end if
end function
rem —取到系统脚本转换字符串—
code copy …
function system(text)
if instr(text,"nt 5.1")>0 then
system=system+"windows xp"
elseif instr(text,"nt 5")>0 then
system=system+"windows 2000"
elseif instr(text,"nt 4")>0 then
system=system+"windows nt4"
elseif instr(text,"4.9")>0 then
system=system+"windows me"
elseif instr(text,"98")>0 then
system=system+"windows 98"
elseif instr(text,"95")>0 then
system=system+"windows 95"
else
system=system+"未知"
end if
end function
rem —=删除文件—
code copy …
function delfile(filepath)
imangepath=trim(filepath)
path=server.mappath(imangepath)
set fs=server.createobject("scripting.filesystemobject")
if fs.fileexists(path) then
fs.deletefile(path)
end if
set fs=nothing
end function
rem —得到真实的客户端ip—
code copy …
public function getclientip()
dim uipaddr
本函数参考webcn.net/asphouse 文献<取真实的客户ip>
uipaddr = request.servervariables("http_x_forwarded_for")
if uipaddr = "" then uipaddr = request.servervariables("remote_addr")
getclientip = uipaddr
uipaddr = ""
end function
数据库查询中的特殊字符的问题
在进行数据库的查询时,会经常遇到这样的情况:
例如想在一个用户数据库中查询他的用户名和他的密码,但恰好该用户使用的名字和密码中有特殊的字符,例如单引号,“|”号,双引号或者连字符“&”。
例如他的名字是1"test,密码是a|&900
这时当你执行以下的查询语句时,肯定会报错:
sql = "select * from securitylevel where uid="" & userid & """
sql = sql & " and pwd="" & password & """
因为你的sql将会是这样:
select * from securitylevel where uid="1"test" and pwd="a|&900"
在sql中,"|"为分割字段用的,显然会出错了。现在提供下面的几个函数 专门用来处理这些头疼的东西:
quoted from unkown:
function replacestr (textin, byval searchstr as string, _
byval replacement as string, _
byval compmode as integer)
dim worktext as string, pointer as integer
if isnull(textin) then
replacestr = null
else
worktext = textin
pointer = instr(1, worktext, searchstr, compmode)
do while pointer > 0
worktext = left(worktext, pointer – 1) & replacement & _
mid(worktext, pointer + len(searchstr))
pointer = instr(pointer + len(replacement), worktext, searchstr, compmode)
loop
replacestr = worktext
end if
end function
function sqlfixup(textin)
sqlfixup = replacestr(textin, """, """", 0)
end function
function jetsqlfixup(textin)
dim temp
temp = replacestr(textin, """, """", 0)
jetsqlfixup = replacestr(temp, "|", "" & chr(124) & "", 0)
end function
function findfirstfixup(textin)
dim temp
temp = replacestr(textin, """, "" & chr(39) & "", 0)
findfirstfixup = replacestr(temp, "|", "" & chr(124) & "", 0)
end function
rem 借助recordset将二进制流转化成文本
quoted from unkown:
function binarytostring(bidata,size)
const adlongvarchar = 201
set rs = createobject("adodb.recordset")
rs.fields.append "mbinary", adlongvarchar, size
rs.open
rs.addnew
rs("mbinary").appendchunk(bidata)
rs.update
binarytostring = rs("mbinary").value
rs.close
end function