ASP常用函数收藏乱七八糟未整理版
程序员文章站
2023-11-16 22:45:58
<% '******************************************************************* '取得ip地址 '**...
<%
'*******************************************************************
'取得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
'*******************************************************************
'转换ip地址
'*******************************************************************
function cip(sip)
tip = cstr(sip)
sip1 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip2 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip3 = left(tip, cint(instr(tip, ".") -1))
sip4 = mid(tip, cint(instr(tip, ".") + 1))
cip = cint(sip1) * 256 * 256 * 256 + cint(sip2) * 256 * 256 + cint(sip3) * 256 + cint(sip4)
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
'*******************************************************************
' 我比较喜欢将以上三个结合起来使用
'*******************************************************************
function alert(message, gourl)
message = replace(message, "'", "\'")
if gourl = "-1" then
response.write ("<script language=javascript>alert('" & message & "');history.go(-1)</script>")
else
response.write ("<script language=javascript>alert('" & message & "');location='" & gourl &"'</script>")
end if
response.end()
end function
'*******************************************************************
' 指定秒数重定向另外的连接
'*******************************************************************
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, ">", ">")
fstring = replace(fstring, "<", "<")
fstring = replace(fstring, chr(32), " ")
fstring = replace(fstring, chr(9), " ")
fstring = replace(fstring, chr(34), """)
fstring = replace(fstring, chr(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
%>
<%
1.检查是否有效邮件地址
function checkemail(stremail)
dim re
set re = new regexp
re.pattern = "^[w-.]{1,}@([da-za-z-]{1,}.){1,}[da-za-z-]{2,3}$"
re.ignorecase = true
checkemail = re.test(stremail)
end function
2.测试变量是否为空值,空值的含义包括:变量不存在 / 为空,对象为nothing,0,空数组,字符串为空
function isblank(byref var)
isblank = false
select case true
case isobject(var)
if var is nothing then isblank = true
case isempty(var), isnull(var)
isblank = true
case isarray(var)
if ubound(var) = 0 then isblank = true
case isnumeric(var)
if (var = 0) then isblank = true
case else
if trim(var) = "" then isblank = true
end select
end function
3.得到浏览器目前的url
function getcururl()
if request.servervariables("https") = "on" then
getcurrenturl = "https://"
else
getcurrenturl = "http://"
end if
getcururl = getcururl & request.servervariables("server_name")
if (request.servervariables("server_port") <> 80) then getcururl = getcururl & ":" & request.servervariables("server_port")
getcururl = getcururl & request.servervariables("url")
if (request.querystring <> "") then getcururl = getcururl & "?" & request.querystring
end function
4.md5加密函数
private const bits_to_a_byte = 8
private const bytes_to_a_word = 4
private const bits_to_a_word = 32
private m_lonbits(30)
private m_l2power(30)
m_lonbits(0) = clng(1)
m_lonbits(1) = clng(3)
m_lonbits(2) = clng(7)
m_lonbits(3) = clng(15)
m_lonbits(4) = clng(31)
m_lonbits(5) = clng(63)
m_lonbits(6) = clng(127)
m_lonbits(7) = clng(255)
m_lonbits(8) = clng(511)
m_lonbits(9) = clng(1023)
m_lonbits(10) = clng(2047)
m_lonbits(11) = clng(4095)
m_lonbits(12) = clng(8191)
m_lonbits(13) = clng(16383)
m_lonbits(14) = clng(32767)
m_lonbits(15) = clng(65535)
m_lonbits(16) = clng(131071)
m_lonbits(17) = clng(262143)
m_lonbits(18) = clng(524287)
m_lonbits(19) = clng(1048575)
m_lonbits(20) = clng(2097151)
m_lonbits(21) = clng(4194303)
m_lonbits(22) = clng(8388607)
m_lonbits(23) = clng(16777215)
m_lonbits(24) = clng(33554431)
m_lonbits(25) = clng(67108863)
m_lonbits(26) = clng(134217727)
m_lonbits(27) = clng(268435455)
m_lonbits(28) = clng(536870911)
m_lonbits(29) = clng(1073741823)
m_lonbits(30) = clng(2147483647)
m_l2power(0) = clng(1)
m_l2power(1) = clng(2)
m_l2power(2) = clng(4)
m_l2power(3) = clng(8)
m_l2power(4) = clng(16)
m_l2power(5) = clng(32)
m_l2power(6) = clng(64)
m_l2power(7) = clng(128)
m_l2power(8) = clng(256)
m_l2power(9) = clng(512)
m_l2power(10) = clng(1024)
m_l2power(11) = clng(2048)
m_l2power(12) = clng(4096)
m_l2power(13) = clng(8192)
m_l2power(14) = clng(16384)
m_l2power(15) = clng(32768)
m_l2power(16) = clng(65536)
m_l2power(17) = clng(131072)
m_l2power(18) = clng(262144)
m_l2power(19) = clng(524288)
m_l2power(20) = clng(1048576)
m_l2power(21) = clng(2097152)
m_l2power(22) = clng(4194304)
m_l2power(23) = clng(8388608)
m_l2power(24) = clng(16777216)
m_l2power(25) = clng(33554432)
m_l2power(26) = clng(67108864)
m_l2power(27) = clng(134217728)
m_l2power(28) = clng(268435456)
m_l2power(29) = clng(536870912)
m_l2power(30) = clng(1073741824)
private function lshift(lvalue, ishiftbits)
if ishiftbits = 0 then
lshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and 1 then
lshift = &h80000000
else
lshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
if (lvalue and m_l2power(31 - ishiftbits)) then
lshift = ((lvalue and m_lonbits(31 - (ishiftbits + 1))) * m_l2power(ishiftbits)) or &h80000000
else
lshift = ((lvalue and m_lonbits(31 - ishiftbits)) * m_l2power(ishiftbits))
end if
end function
private function rshift(lvalue, ishiftbits)
if ishiftbits = 0 then
rshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and &h80000000 then
rshift = 1
else
rshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
rshift = (lvalue and &h7ffffffe) m_l2power(ishiftbits)
if (lvalue and &h80000000) then
rshift = (rshift or (&h40000000 m_l2power(ishiftbits - 1)))
end if
end function
private function rotateleft(lvalue, ishiftbits)
rotateleft = lshift(lvalue, ishiftbits) or rshift(lvalue, (32 - ishiftbits))
end function
private function addunsigned(lx, ly)
dim lx4
dim ly4
dim lx8
dim ly8
dim lresult
lx8 = lx and &h80000000
ly8 = ly and &h80000000
lx4 = lx and &h40000000
ly4 = ly and &h40000000
lresult = (lx and &h3fffffff) + (ly and &h3fffffff)
if lx4 and ly4 then
lresult = lresult xor &h80000000 xor lx8 xor ly8
elseif lx4 or ly4 then
if lresult and &h40000000 then
lresult = lresult xor &hc0000000 xor lx8 xor ly8
else
lresult = lresult xor &h40000000 xor lx8 xor ly8
end if
else
lresult = lresult xor lx8 xor ly8
end if
addunsigned = lresult
end function
private function f(x, y, z)
f = (x and y) or ((not x) and z)
end function
private function g(x, y, z)
g = (x and z) or (y and (not z))
end function
private function h(x, y, z)
h = (x xor y xor z)
end function
private function i(x, y, z)
i = (y xor (x or (not z)))
end function
private sub ff(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(f(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private sub gg(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(g(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private sub hh(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(h(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private sub ii(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(i(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private function converttowordarray(smessage)
dim lmessagelength
dim lnumberofwords
dim lwordarray()
dim lbyteposition
dim lbytecount
dim lwordcount
const modulus_bits = 512
const congruent_bits = 448
lmessagelength = len(smessage)
lnumberofwords = (((lmessagelength + ((modulus_bits - congruent_bits) bits_to_a_byte)) (modulus_bits bits_to_a_byte)) + 1) * (modulus_bits bits_to_a_word)
redim lwordarray(lnumberofwords - 1)
lbyteposition = 0
lbytecount = 0
do until lbytecount >= lmessagelength
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (lbytecount mod bytes_to_a_word) * bits_to_a_byte
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(asc(mid(smessage, lbytecount + 1, 1)), lbyteposition)
lbytecount = lbytecount + 1
loop
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (lbytecount mod bytes_to_a_word) * bits_to_a_byte
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(&h80, lbyteposition)
lwordarray(lnumberofwords - 2) = lshift(lmessagelength, 3)
lwordarray(lnumberofwords - 1) = rshift(lmessagelength, 29)
converttowordarray = lwordarray
end function
private function wordtohex(lvalue)
dim lbyte
dim lcount
for lcount = 0 to 3
lbyte = rshift(lvalue, lcount * bits_to_a_byte) and m_lonbits(bits_to_a_byte - 1)
wordtohex = wordtohex & right("0" & hex(lbyte), 2)
next
end function
public function md5(smessage)
dim x
dim k
dim aa
dim bb
dim cc
dim dd
dim a
dim b
dim c
dim d
const s11 = 7
const s12 = 12
const s13 = 17
const s14 = 22
const s21 = 5
const s22 = 9
const s23 = 14
const s24 = 20
const s31 = 4
const s32 = 11
const s33 = 16
const s34 = 23
const s41 = 6
const s42 = 10
const s43 = 15
const s44 = 21
x = converttowordarray(smessage)
a = &h67452301
b = &hefcdab89
c = &h98badcfe
d = &h10325476
for k = 0 to ubound(x) step 16
aa = a
bb = b
cc = c
dd = d
ff a, b, c, d, x(k + 0), s11, &hd76aa478
ff d, a, b, c, x(k + 1), s12, &he8c7b756
ff c, d, a, b, x(k + 2), s13, &h242070db
ff b, c, d, a, x(k + 3), s14, &hc1bdceee
ff a, b, c, d, x(k + 4), s11, &hf57c0faf
ff d, a, b, c, x(k + 5), s12, &h4787c62a
ff c, d, a, b, x(k + 6), s13, &ha8304613
ff b, c, d, a, x(k + 7), s14, &hfd469501
ff a, b, c, d, x(k + 8), s11, &h698098d8
ff d, a, b, c, x(k + 9), s12, &h8b44f7af
ff c, d, a, b, x(k + 10), s13, &hffff5bb1
ff b, c, d, a, x(k + 11), s14, &h895cd7be
ff a, b, c, d, x(k + 12), s11, &h6b901122
ff d, a, b, c, x(k + 13), s12, &hfd987193
ff c, d, a, b, x(k + 14), s13, &ha679438e
ff b, c, d, a, x(k + 15), s14, &h49b40821
gg a, b, c, d, x(k + 1), s21, &hf61e2562
gg d, a, b, c, x(k + 6), s22, &hc040b340
gg c, d, a, b, x(k + 11), s23, &h265e5a51
gg b, c, d, a, x(k + 0), s24, &he9b6c7aa
gg a, b, c, d, x(k + 5), s21, &hd62f105d
gg d, a, b, c, x(k + 10), s22, &h2441453
gg c, d, a, b, x(k + 15), s23, &hd8a1e681
gg b, c, d, a, x(k + 4), s24, &he7d3fbc8
gg a, b, c, d, x(k + 9), s21, &h21e1cde6
gg d, a, b, c, x(k + 14), s22, &hc33707d6
gg c, d, a, b, x(k + 3), s23, &hf4d50d87
gg b, c, d, a, x(k + 8), s24, &h455a14ed
gg a, b, c, d, x(k + 13), s21, &ha9e3e905
gg d, a, b, c, x(k + 2), s22, &hfcefa3f8
gg c, d, a, b, x(k + 7), s23, &h676f02d9
gg b, c, d, a, x(k + 12), s24, &h8d2a4c8a
hh a, b, c, d, x(k + 5), s31, &hfffa3942
hh d, a, b, c, x(k + 8), s32, &h8771f681
hh c, d, a, b, x(k + 11), s33, &h6d9d6122
hh b, c, d, a, x(k + 14), s34, &hfde5380c
hh a, b, c, d, x(k + 1), s31, &ha4beea44
hh d, a, b, c, x(k + 4), s32, &h4bdecfa9
hh c, d, a, b, x(k + 7), s33, &hf6bb4b60
hh b, c, d, a, x(k + 10), s34, &hbebfbc70
hh a, b, c, d, x(k + 13), s31, &h289b7ec6
hh d, a, b, c, x(k + 0), s32, &heaa127fa
hh c, d, a, b, x(k + 3), s33, &hd4ef3085
hh b, c, d, a, x(k + 6), s34, &h4881d05
hh a, b, c, d, x(k + 9), s31, &hd9d4d039
hh d, a, b, c, x(k + 12), s32, &he6db99e5
hh c, d, a, b, x(k + 15), s33, &h1fa27cf8
hh b, c, d, a, x(k + 2), s34, &hc4ac5665
ii a, b, c, d, x(k + 0), s41, &hf4292244
ii d, a, b, c, x(k + 7), s42, &h432aff97
ii c, d, a, b, x(k + 14), s43, &hab9423a7
ii b, c, d, a, x(k + 5), s44, &hfc93a039
ii a, b, c, d, x(k + 12), s41, &h655b59c3
ii d, a, b, c, x(k + 3), s42, &h8f0ccc92
ii c, d, a, b, x(k + 10), s43, &hffeff47d
ii b, c, d, a, x(k + 1), s44, &h85845dd1
ii a, b, c, d, x(k + 8), s41, &h6fa87e4f
ii d, a, b, c, x(k + 15), s42, &hfe2ce6e0
ii c, d, a, b, x(k + 6), s43, &ha3014314
ii b, c, d, a, x(k + 13), s44, &h4e0811a1
ii a, b, c, d, x(k + 4), s41, &hf7537e82
ii d, a, b, c, x(k + 11), s42, &hbd3af235
ii c, d, a, b, x(k + 2), s43, &h2ad7d2bb
ii b, c, d, a, x(k + 9), s44, &heb86d391
a = addunsigned(a, aa)
b = addunsigned(b, bb)
c = addunsigned(c, cc)
d = addunsigned(d, dd)
next
md5 = lcase(wordtohex(a) & wordtohex(b) & wordtohex(c) & wordtohex(d))
end function
5.sha256 加密,256位的加密哦!安全性更高!
private m_lonbits(30)
private m_l2power(30)
private k(63)
private const bits_to_a_byte = 8
private const bytes_to_a_word = 4
private const bits_to_a_word = 32
m_lonbits(0) = clng(1)
m_lonbits(1) = clng(3)
m_lonbits(2) = clng(7)
m_lonbits(3) = clng(15)
m_lonbits(4) = clng(31)
m_lonbits(5) = clng(63)
m_lonbits(6) = clng(127)
m_lonbits(7) = clng(255)
m_lonbits(8) = clng(511)
m_lonbits(9) = clng(1023)
m_lonbits(10) = clng(2047)
m_lonbits(11) = clng(4095)
m_lonbits(12) = clng(8191)
m_lonbits(13) = clng(16383)
m_lonbits(14) = clng(32767)
m_lonbits(15) = clng(65535)
m_lonbits(16) = clng(131071)
m_lonbits(17) = clng(262143)
m_lonbits(18) = clng(524287)
m_lonbits(19) = clng(1048575)
m_lonbits(20) = clng(2097151)
m_lonbits(21) = clng(4194303)
m_lonbits(22) = clng(8388607)
m_lonbits(23) = clng(16777215)
m_lonbits(24) = clng(33554431)
m_lonbits(25) = clng(67108863)
m_lonbits(26) = clng(134217727)
m_lonbits(27) = clng(268435455)
m_lonbits(28) = clng(536870911)
m_lonbits(29) = clng(1073741823)
m_lonbits(30) = clng(2147483647)
m_l2power(0) = clng(1)
m_l2power(1) = clng(2)
m_l2power(2) = clng(4)
m_l2power(3) = clng(8)
m_l2power(4) = clng(16)
m_l2power(5) = clng(32)
m_l2power(6) = clng(64)
m_l2power(7) = clng(128)
m_l2power(8) = clng(256)
m_l2power(9) = clng(512)
m_l2power(10) = clng(1024)
m_l2power(11) = clng(2048)
m_l2power(12) = clng(4096)
m_l2power(13) = clng(8192)
m_l2power(14) = clng(16384)
m_l2power(15) = clng(32768)
m_l2power(16) = clng(65536)
m_l2power(17) = clng(131072)
m_l2power(18) = clng(262144)
m_l2power(19) = clng(524288)
m_l2power(20) = clng(1048576)
m_l2power(21) = clng(2097152)
m_l2power(22) = clng(4194304)
m_l2power(23) = clng(8388608)
m_l2power(24) = clng(16777216)
m_l2power(25) = clng(33554432)
m_l2power(26) = clng(67108864)
m_l2power(27) = clng(134217728)
m_l2power(28) = clng(268435456)
m_l2power(29) = clng(536870912)
m_l2power(30) = clng(1073741824)
k(0) = &h428a2f98
k(1) = &h71374491
k(2) = &hb5c0fbcf
k(3) = &he9b5dba5
k(4) = &h3956c25b
k(5) = &h59f111f1
k(6) = &h923f82a4
k(7) = &hab1c5ed5
k(8) = &hd807aa98
k(9) = &h12835b01
k(10) = &h243185be
k(11) = &h550c7dc3
k(12) = &h72be5d74
k(13) = &h80deb1fe
k(14) = &h9bdc06a7
k(15) = &hc19bf174
k(16) = &he49b69c1
k(17) = &hefbe4786
k(18) = &hfc19dc6
k(19) = &h240ca1cc
k(20) = &h2de92c6f
k(21) = &h4a7484aa
k(22) = &h5cb0a9dc
k(23) = &h76f988da
k(24) = &h983e5152
k(25) = &ha831c66d
k(26) = &hb00327c8
k(27) = &hbf597fc7
k(28) = &hc6e00bf3
k(29) = &hd5a79147
k(30) = &h6ca6351
k(31) = &h14292967
k(32) = &h27b70a85
k(33) = &h2e1b2138
k(34) = &h4d2c6dfc
k(35) = &h53380d13
k(36) = &h650a7354
k(37) = &h766a0abb
k(38) = &h81c2c92e
k(39) = &h92722c85
k(40) = &ha2bfe8a1
k(41) = &ha81a664b
k(42) = &hc24b8b70
k(43) = &hc76c51a3
k(44) = &hd192e819
k(45) = &hd6990624
k(46) = &hf40e3585
k(47) = &h106aa070
k(48) = &h19a4c116
k(49) = &h1e376c08
k(50) = &h2748774c
k(51) = &h34b0bcb5
k(52) = &h391c0cb3
k(53) = &h4ed8aa4a
k(54) = &h5b9cca4f
k(55) = &h682e6ff3
k(56) = &h748f82ee
k(57) = &h78a5636f
k(58) = &h84c87814
k(59) = &h8cc70208
k(60) = &h90befffa
k(61) = &ha4506ceb
k(62) = &hbef9a3f7
k(63) = &hc67178f2
private function lshift(lvalue, ishiftbits)
if ishiftbits = 0 then
lshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and 1 then
lshift = &h80000000
else
lshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
if (lvalue and m_l2power(31 - ishiftbits)) then
lshift = ((lvalue and m_lonbits(31 - (ishiftbits + 1))) * m_l2power(ishiftbits)) or &h80000000
else
lshift = ((lvalue and m_lonbits(31 - ishiftbits)) * m_l2power(ishiftbits))
end if
end function
private function rshift(lvalue, ishiftbits)
if ishiftbits = 0 then
rshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and &h80000000 then
rshift = 1
else
rshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
rshift = (lvalue and &h7ffffffe) m_l2power(ishiftbits)
if (lvalue and &h80000000) then
rshift = (rshift or (&h40000000 m_l2power(ishiftbits - 1)))
end if
end function
private function addunsigned(lx, ly)
dim lx4
dim ly4
dim lx8
dim ly8
dim lresult
lx8 = lx and &h80000000
ly8 = ly and &h80000000
lx4 = lx and &h40000000
ly4 = ly and &h40000000
lresult = (lx and &h3fffffff) + (ly and &h3fffffff)
if lx4 and ly4 then
lresult = lresult xor &h80000000 xor lx8 xor ly8
elseif lx4 or ly4 then
if lresult and &h40000000 then
lresult = lresult xor &hc0000000 xor lx8 xor ly8
else
lresult = lresult xor &h40000000 xor lx8 xor ly8
end if
else
lresult = lresult xor lx8 xor ly8
end if
addunsigned = lresult
end function
private function ch(x, y, z)
ch = ((x and y) xor ((not x) and z))
end function
private function maj(x, y, z)
maj = ((x and y) xor (x and z) xor (y and z))
end function
private function s(x, n)
s = (rshift(x, (n and m_lonbits(4))) or lshift(x, (32 - (n and m_lonbits(4)))))
end function
private function r(x, n)
r = rshift(x, cint(n and m_lonbits(4)))
end function
private function sigma0(x)
sigma0 = (s(x, 2) xor s(x, 13) xor s(x, 22))
end function
private function sigma1(x)
sigma1 = (s(x, 6) xor s(x, 11) xor s(x, 25))
end function
private function gamma0(x)
gamma0 = (s(x, 7) xor s(x, 18) xor r(x, 3))
end function
private function gamma1(x)
gamma1 = (s(x, 17) xor s(x, 19) xor r(x, 10))
end function
private function converttowordarray(smessage)
dim lmessagelength
dim lnumberofwords
dim lwordarray()
dim lbyteposition
dim lbytecount
dim lwordcount
dim lbyte
const modulus_bits = 512
const congruent_bits = 448
lmessagelength = len(smessage)
lnumberofwords = (((lmessagelength + ((modulus_bits - congruent_bits) bits_to_a_byte)) (modulus_bits bits_to_a_byte)) + 1) * (modulus_bits bits_to_a_word)
redim lwordarray(lnumberofwords - 1)
lbyteposition = 0
lbytecount = 0
do until lbytecount >= lmessagelength
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (3 - (lbytecount mod bytes_to_a_word)) * bits_to_a_byte
lbyte = ascb(mid(smessage, lbytecount + 1, 1))
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(lbyte, lbyteposition)
lbytecount = lbytecount + 1
loop
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (3 - (lbytecount mod bytes_to_a_word)) * bits_to_a_byte
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(&h80, lbyteposition)
lwordarray(lnumberofwords - 1) = lshift(lmessagelength, 3)
lwordarray(lnumberofwords - 2) = rshift(lmessagelength, 29)
converttowordarray = lwordarray
end function
public function sha256(smessage)
dim hash(7)
dim m
dim w(63)
dim a
dim b
dim c
dim d
dim e
dim f
dim g
dim h
dim i
dim j
dim t1
dim t2
hash(0) = &h6a09e667
hash(1) = &hbb67ae85
hash(2) = &h3c6ef372
hash(3) = &ha54ff53a
hash(4) = &h510e527f
hash(5) = &h9b05688c
hash(6) = &h1f83d9ab
hash(7) = &h5be0cd19
m = converttowordarray(smessage)
for i = 0 to ubound(m) step 16
a = hash(0)
b = hash(1)
c = hash(2)
d = hash(3)
e = hash(4)
f = hash(5)
g = hash(6)
h = hash(7)
for j = 0 to 63
if j < 16 then
w(j) = m(j + i)
else
w(j) = addunsigned(addunsigned(addunsigned(gamma1(w(j - 2)), w(j - 7)), gamma0(w(j - 15))), w(j - 16))
end if
t1 = addunsigned(addunsigned(addunsigned(addunsigned(h, sigma1(e)), ch(e, f, g)), k(j)), w(j))
t2 = addunsigned(sigma0(a), maj(a, b, c))
h = g
g = f
f = e
e = addunsigned(d, t1)
d = c
c = b
b = a
a = addunsigned(t1, t2)
next
hash(0) = addunsigned(a, hash(0))
hash(1) = addunsigned(b, hash(1))
hash(2) = addunsigned(c, hash(2))
hash(3) = addunsigned(d, hash(3))
hash(4) = addunsigned(e, hash(4))
hash(5) = addunsigned(f, hash(5))
hash(6) = addunsigned(g, hash(6))
hash(7) = addunsigned(h, hash(7))
next
sha256 = lcase(right("00000000" & hex(hash(0)), 8) & right("00000000" & hex(hash(1)), 8) & right("00000000" & hex(hash(2)), 8) & right("00000000" & hex(hash(3)), 8) & right("00000000" & hex(hash(4)), 8) & right("00000000" & hex(hash(5)), 8) & right("00000000" & hex(hash(6)), 8) & right("00000000" & hex(hash(7)), 8))
end function
6.一个if语句的加工,以后可以用类似于php或js的 if () ? ..
...代码了
function iif(condition, valueiftrue, valueiffalse)
if condition then
iif = valueiftrue
else
iif = valueiffalse
end if
end function
7.ase加密函数
private m_lonbits(30)
private m_l2power(30)
private m_bytonbits(7)
private m_byt2power(7)
private m_inco(3)
private m_fbsub(255)
private m_rbsub(255)
private m_ptab(255)
private m_ltab(255)
private m_ftable(255)
private m_rtable(255)
private m_rco(29)
private m_nk
private m_nb
private m_nr
private m_fi(23)
private m_ri(23)
private m_fkey(119)
private m_rkey(119)
m_inco(0) = &hb
m_inco(1) = &hd
m_inco(2) = &h9
m_inco(3) = &he
m_bytonbits(0) = 1
m_bytonbits(1) = 3
m_bytonbits(2) = 7
m_bytonbits(3) = 15
m_bytonbits(4) = 31
m_bytonbits(5) = 63
m_bytonbits(6) = 127
m_bytonbits(7) = 255
m_byt2power(0) = 1
m_byt2power(1) = 2
m_byt2power(2) = 4
m_byt2power(3) = 8
m_byt2power(4) = 16
m_byt2power(5) = 32
m_byt2power(6) = 64
m_byt2power(7) = 128
m_lonbits(0) = 1
m_lonbits(1) = 3
m_lonbits(2) = 7
m_lonbits(3) = 15
m_lonbits(4) = 31
m_lonbits(5) = 63
m_lonbits(6) = 127
m_lonbits(7) = 255
m_lonbits(8) = 511
m_lonbits(9) = 1023
m_lonbits(10) = 2047
m_lonbits(11) = 4095
m_lonbits(12) = 8191
m_lonbits(13) = 16383
m_lonbits(14) = 32767
m_lonbits(15) = 65535
m_lonbits(16) = 131071
m_lonbits(17) = 262143
m_lonbits(18) = 524287
m_lonbits(19) = 1048575
m_lonbits(20) = 2097151
m_lonbits(21) = 4194303
m_lonbits(22) = 8388607
m_lonbits(23) = 16777215
m_lonbits(24) = 33554431
m_lonbits(25) = 67108863
m_lonbits(26) = 134217727
m_lonbits(27) = 268435455
m_lonbits(28) = 536870911
m_lonbits(29) = 1073741823
m_lonbits(30) = 2147483647
m_l2power(0) = 1
m_l2power(1) = 2
m_l2power(2) = 4
m_l2power(3) = 8
m_l2power(4) = 16
m_l2power(5) = 32
m_l2power(6) = 64
m_l2power(7) = 128
m_l2power(8) = 256
m_l2power(9) = 512
m_l2power(10) = 1024
m_l2power(11) = 2048
m_l2power(12) = 4096
m_l2power(13) = 8192
m_l2power(14) = 16384
m_l2power(15) = 32768
m_l2power(16) = 65536
m_l2power(17) = 131072
m_l2power(18) = 262144
m_l2power(19) = 524288
m_l2power(20) = 1048576
m_l2power(21) = 2097152
m_l2power(22) = 4194304
m_l2power(23) = 8388608
m_l2power(24) = 16777216
m_l2power(25) = 33554432
m_l2power(26) = 67108864
m_l2power(27) = 134217728
m_l2power(28) = 268435456
m_l2power(29) = 536870912
m_l2power(30) = 1073741824
private function lshift(lvalue, ishiftbits)
if ishiftbits = 0 then
lshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and 1 then
lshift = &h80000000
else
lshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
if (lvalue and m_l2power(31 - ishiftbits)) then
lshift = ((lvalue and m_lonbits(31 - (ishiftbits + 1))) * m_l2power(ishiftbits)) or &h80000000
else
lshift = ((lvalue and m_lonbits(31 - ishiftbits)) * m_l2power(ishiftbits))
end if
end function
private function rshift(lvalue, ishiftbits)
if ishiftbits = 0 then
rshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and &h80000000 then
rshift = 1
else
rshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
rshift = (lvalue and &h7ffffffe) m_l2power(ishiftbits)
if (lvalue and &h80000000) then
rshift = (rshift or (&h40000000 m_l2power(ishiftbits - 1)))
end if
end function
private function lshiftbyte(bytvalue, bytshiftbits)
if bytshiftbits = 0 then
lshiftbyte = bytvalue
exit function
elseif bytshiftbits = 7 then
if bytvalue and 1 then
lshiftbyte = &h80
else
lshiftbyte = 0
end if
exit function
elseif bytshiftbits < 0 or bytshiftbits > 7 then
err.raise 6
end if
lshiftbyte = ((bytvalue and m_bytonbits(7 - bytshiftbits)) * m_byt2power(bytshiftbits))
end function
private function rshiftbyte(bytvalue, bytshiftbits)
if bytshiftbits = 0 then
rshiftbyte = bytvalue
exit function
elseif bytshiftbits = 7 then
if bytvalue and &h80 then
rshiftbyte = 1
else
rshiftbyte = 0
end if
exit function
elseif bytshiftbits < 0 or bytshiftbits > 7 then
err.raise 6
end if
rshiftbyte = bytvalue m_byt2power(bytshiftbits)
end function
private function rotateleft(lvalue, ishiftbits)
rotateleft = lshift(lvalue, ishiftbits) or rshift(lvalue, (32 - ishiftbits))
end function
private function rotateleftbyte(bytvalue, bytshiftbits)
rotateleftbyte = lshiftbyte(bytvalue, bytshiftbits) or rshiftbyte(bytvalue, (8 - bytshiftbits))
end function
private function pack(b())
dim lcount
dim ltemp
for lcount = 0 to 3
ltemp = b(lcount)
pack = pack or lshift(ltemp, (lcount * 8))
next
end function
private function packfrom(b(), k)
dim lcount
dim ltemp
for lcount = 0 to 3
ltemp = b(lcount + k)
packfrom = packfrom or lshift(ltemp, (lcount * 8))
next
end function
private sub unpack(a, b())
b(0) = a and m_lonbits(7)
b(1) = rshift(a, 8) and m_lonbits(7)
b(2) = rshift(a, 16) and m_lonbits(7)
b(3) = rshift(a, 24) and m_lonbits(7)
end sub
private sub unpackfrom(a, b(), k)
b(0 + k) = a and m_lonbits(7)
b(1 + k) = rshift(a, 8) and m_lonbits(7)
b(2 + k) = rshift(a, 16) and m_lonbits(7)
b(3 + k) = rshift(a, 24) and m_lonbits(7)
end sub
private function xtime(a)
dim b
if (a and &h80) then
b = &h1b
else
b = 0
end if
xtime = lshiftbyte(a, 1)
xtime = xtime xor b
end function
private function bmul(x, y)
if x <> 0 and y <> 0 then
bmul = m_ptab((clng(m_ltab(x)) + clng(m_ltab(y))) mod 255)
else
bmul = 0
end if
end function
private function subbyte(a)
dim b(3)
unpack a, b
b(0) = m_fbsub(b(0))
b(1) = m_fbsub(b(1))
b(2) = m_fbsub(b(2))
b(3) = m_fbsub(b(3))
subbyte = pack(b)
end function
private function product(x, y)
dim xb(3)
dim yb(3)
unpack x, xb
unpack y, yb
product = bmul(xb(0), yb(0)) xor bmul(xb(1), yb(1)) xor bmul(xb(2), yb(2)) xor bmul(xb(3), yb(3))
end function
private function invmixcol(x)
dim y
dim m
dim b(3)
m = pack(m_inco)
b(3) = product(m, x)
m = rotateleft(m, 24)
b(2) = product(m, x)
m = rotateleft(m, 24)
b(1) = product(m, x)
m = rotateleft(m, 24)
b(0) = product(m, x)
y = pack(b)
invmixcol = y
end function
private function bytesub(x)
dim y
dim z
z = x
y = m_ptab(255 - m_ltab(z))
z = y
z = rotateleftbyte(z, 1)
y = y xor z
z = rotateleftbyte(z, 1)
y = y xor z
z = rotateleftbyte(z, 1)
y = y xor z
z = rotateleftbyte(z, 1)
y = y xor z
y = y xor &h63
bytesub = y
end function
public sub gentables()
dim i
dim y
dim b(3)
dim ib
m_ltab(0) = 0
m_ptab(0) = 1
m_ltab(1) = 0
m_ptab(1) = 3
m_ltab(3) = 1
for i = 2 to 255
m_ptab(i) = m_ptab(i - 1) xor xtime(m_ptab(i - 1))
m_ltab(m_ptab(i)) = i
next
m_fbsub(0) = &h63
m_rbsub(&h63) = 0
for i = 1 to 255
ib = i
y = bytesub(ib)
m_fbsub(i) = y
m_rbsub(y) = i
next
y = 1
for i = 0 to 29
m_rco(i) = y
y = xtime(y)
next
for i = 0 to 255
y = m_fbsub(i)
b(3) = y xor xtime(y)
b(2) = y
b(1) = y
b(0) = xtime(y)
m_ftable(i) = pack(b)
y = m_rbsub(i)
b(3) = bmul(m_inco(0), y)
b(2) = bmul(m_inco(1), y)
b(1) = bmul(m_inco(2), y)
b(0) = bmul(m_inco(3), y)
m_rtable(i) = pack(b)
next
end sub
public sub gkey(nb, nk, key())
dim i
dim j
dim k
dim m
dim n
dim c1
dim c2
dim c3
dim cipherkey(7)
m_nb = nb
m_nk = nk
if m_nb >= m_nk then
m_nr = 6 + m_nb
else
m_nr = 6 + m_nk
end if
c1 = 1
if m_nb < 8 then
c2 = 2
c3 = 3
else
c2 = 3
c3 = 4
end if
for j = 0 to nb - 1
m = j * 3
m_fi(m) = (j + c1) mod nb
m_fi(m + 1) = (j + c2) mod nb
m_fi(m + 2) = (j + c3) mod nb
m_ri(m) = (nb + j - c1) mod nb
m_ri(m + 1) = (nb + j - c2) mod nb
m_ri(m + 2) = (nb + j - c3) mod nb
next
n = m_nb * (m_nr + 1)
for i = 0 to m_nk - 1
j = i * 4
cipherkey(i) = packfrom(key, j)
next
for i = 0 to m_nk - 1
m_fkey(i) = cipherkey(i)
next
j = m_nk
k = 0
do while j < n
m_fkey(j) = m_fkey(j - m_nk) xor _
subbyte(rotateleft(m_fkey(j - 1), 24)) xor m_rco(k)
if m_nk <= 6 then
i = 1
do while i < m_nk and (i + j) < n
m_fkey(i + j) = m_fkey(i + j - m_nk) xor _
m_fkey(i + j - 1)
i = i + 1
loop
else
i = 1
do while i < 4 and (i + j) < n
m_fkey(i + j) = m_fkey(i + j - m_nk) xor _
m_fkey(i + j - 1)
i = i + 1
loop
if j + 4 < n then
m_fkey(j + 4) = m_fkey(j + 4 - m_nk) xor _
subbyte(m_fkey(j + 3))
end if
i = 5
do while i < m_nk and (i + j) < n
m_fkey(i + j) = m_fkey(i + j - m_nk) xor _
m_fkey(i + j - 1)
i = i + 1
loop
end if
j = j + m_nk
k = k + 1
loop
for j = 0 to m_nb - 1
m_rkey(j + n - nb) = m_fkey(j)
next
i = m_nb
do while i < n - m_nb
k = n - m_nb - i
for j = 0 to m_nb - 1
m_rkey(k + j) = invmixcol(m_fkey(i + j))
next
i = i + m_nb
loop
j = n - m_nb
do while j < n
m_rkey(j - n + m_nb) = m_fkey(j)
j = j + 1
loop
end sub
public sub encrypt(buff())
dim i
dim j
dim k
dim m
dim a(7)
dim b(7)
dim x
dim y
dim t
for i = 0 to m_nb - 1
j = i * 4
a(i) = packfrom(buff, j)
a(i) = a(i) xor m_fkey(i)
next
k = m_nb
x = a
y = b
for i = 1 to m_nr - 1
for j = 0 to m_nb - 1
m = j * 3
y(j) = m_fkey(k) xor m_ftable(x(j) and m_lonbits(7)) xor _
rotateleft(m_ftable(rshift(x(m_fi(m)), 8) and m_lonbits(7)), 8) xor _
rotateleft(m_ftable(rshift(x(m_fi(m + 1)), 16) and m_lonbits(7)), 16) xor _
rotateleft(m_ftable(rshift(x(m_fi(m + 2)), 24) and m_lonbits(7)), 24)
k = k + 1
next
t = x
x = y
y = t
next
for j = 0 to m_nb - 1
m = j * 3
y(j) = m_fkey(k) xor m_fbsub(x(j) and m_lonbits(7)) xor _
rotateleft(m_fbsub(rshift(x(m_fi(m)), 8) and m_lonbits(7)), 8) xor _
rotateleft(m_fbsub(rshift(x(m_fi(m + 1)), 16) and m_lonbits(7)), 16) xor _
rotateleft(m_fbsub(rshift(x(m_fi(m + 2)), 24) and m_lonbits(7)), 24)
k = k + 1
next
for i = 0 to m_nb - 1
j = i * 4
unpackfrom y(i), buff, j
x(i) = 0
y(i) = 0
next
end sub
public sub decrypt(buff())
dim i
dim j
dim k
dim m
dim a(7)
dim b(7)
dim x
dim y
dim t
for i = 0 to m_nb - 1
j = i * 4
a(i) = packfrom(buff, j)
a(i) = a(i) xor m_rkey(i)
next
k = m_nb
x = a
y = b
for i = 1 to m_nr - 1
for j = 0 to m_nb - 1
m = j * 3
y(j) = m_rkey(k) xor m_rtable(x(j) and m_lonbits(7)) xor _
rotateleft(m_rtable(rshift(x(m_ri(m)), 8) and m_lonbits(7)), 8) xor _
rotateleft(m_rtable(rshift(x(m_ri(m + 1)), 16) and m_lonbits(7)), 16) xor _
rotateleft(m_rtable(rshift(x(m_ri(m + 2)), 24) and m_lonbits(7)), 24)
k = k + 1
next
t = x
x = y
y = t
next
for j = 0 to m_nb - 1
m = j * 3
y(j) = m_rkey(k) xor m_rbsub(x(j) and m_lonbits(7)) xor _
rotateleft(m_rbsub(rshift(x(m_ri(m)), 8) and m_lonbits(7)), 8) xor _
rotateleft(m_rbsub(rshift(x(m_ri(m + 1)), 16) and m_lonbits(7)), 16) xor _
rotateleft(m_rbsub(rshift(x(m_ri(m + 2)), 24) and m_lonbits(7)), 24)
k = k + 1
next
for i = 0 to m_nb - 1
j = i * 4
unpackfrom y(i), buff, j
x(i) = 0
y(i) = 0
next
end sub
private function isinitialized(varray)
on error resume next
isinitialized = isnumeric(ubound(varray))
end function
private sub copybytesasp(bytdest, ldeststart, bytsource(), lsourcestart, llength)
dim lcount
lcount = 0
do
bytdest(ldeststart + lcount) = bytsource(lsourcestart + lcount)
lcount = lcount + 1
loop until lcount = llength
end sub
public function encryptdata(bytmessage, bytpassword)
dim bytkey(31)
dim bytin()
dim bytout()
dim byttemp(31)
dim lcount
dim llength
dim lencodedlength
dim bytlen(3)
dim lposition
if not isinitialized(bytmessage) then
exit function
end if
if not isinitialized(bytpassword) then
exit function
end if
for lcount = 0 to ubound(bytpassword)
bytkey(lcount) = bytpassword(lcount)
if lcount = 31 then
exit for
end if
next
gentables
gkey 8, 8, bytkey
llength = ubound(bytmessage) + 1
lencodedlength = llength + 4
if lencodedlength mod 32 <> 0 then
lencodedlength = lencodedlength + 32 - (lencodedlength mod 32)
end if
redim bytin(lencodedlength - 1)
redim bytout(lencodedlength - 1)
unpack llength, bytin
copybytesasp bytin, 4, bytmessage, 0, llength
for lcount = 0 to lencodedlength - 1 step 32
copybytesasp byttemp, 0, bytin, lcount, 32
encrypt byttemp
copybytesasp bytout, lcount, byttemp, 0, 32
next
encryptdata = bytout
end function
public function decryptdata(bytin, bytpassword)
dim bytmessage()
dim bytkey(31)
dim bytout()
dim byttemp(31)
dim lcount
dim llength
dim lencodedlength
dim bytlen(3)
dim lposition
if not isinitialized(bytin) then
exit function
end if
if not isinitialized(bytpassword) then
exit function
end if
lencodedlength = ubound(bytin) + 1
if lencodedlength mod 32 <> 0 then
exit function
end if
for lcount = 0 to ubound(bytpassword)
bytkey(lcount) = bytpassword(lcount)
if lcount = 31 then
exit for
end if
next
gentables
gkey 8, 8, bytkey
redim bytout(lencodedlength - 1)
for lcount = 0 to lencodedlength - 1 step 32
copybytesasp byttemp, 0, bytin, lcount, 32
decrypt byttemp
copybytesasp bytout, lcount, byttemp, 0, 32
next
llength = pack(bytout)
if llength > lencodedlength - 4 then
exit function
end if
redim bytmessage(llength - 1)
copybytesasp bytmessage, 0, bytout, 4, llength
decryptdata = bytmessage
end function
8.一个日期转换函数
function formatdate(byval strdate, byval strformat)
' accepts strdate as a valid date/time,
' strformat as the output template.
' the function finds each item in the
' template and replaces it with the
' relevant information extracted from strdate.
' you are free to use this code provided the following line remains
' www.adopenstatic.com/resources/code/formatdate.asp
' template items
' %m month as a decimal no. 2
' %m month as a padded decimal no. 02
' %b full month name february
' %b abbreviated month name feb
' %d day of the month eg 23
' %d padded day of the month eg 09
' %o ordinal of day of month (eg st or rd or nd)
' %j day of the year 54
' %y year with century 1998
' %y year without century 98
' %w weekday as integer (0 is sunday)
' %a abbreviated day name fri
' %a weekday name friday
' %h hour in 24 hour format 24
' %h hour in 12 hour format 12
' %n minute as an integer 01
' %n minute as optional if minute <> 00
' %s second as an integer 55
' %p am/pm indicator pm
on error resume next
dim intpositem
dim int12hourpart
dim str24hourpart
dim strminutepart
dim strsecondpart
dim strampm
' insert month numbers
strformat = replace(strformat, "%m", datepart("m", strdate), 1, -1, vbbinarycompare)
' insert padded month numbers
strformat = replace(strformat, "%m", right("0" & datepart("m", strdate), 2), 1, -1, vbbinarycompare)
' insert non-abbreviated month names
strformat = replace(strformat, "%b", monthname(datepart("m", strdate), false), 1, -1, vbbinarycompare)
' insert abbreviated month names
strformat = replace(strformat, "%b", monthname(datepart("m", strdate), true), 1, -1, vbbinarycompare)
' insert day of month
strformat = replace(strformat, "%d", datepart("d", strdate), 1, -1, vbbinarycompare)
' insert padded day of month
strformat = replace(strformat, "%d", right ("0" & datepart("d", strdate), 2), 1, -1, vbbinarycompare)
' insert day of month ordinal (eg st, th, or rd)
strformat = replace(strformat, "%o", getdayordinal(day(strdate)), 1, -1, vbbinarycompare)
' insert day of year
strformat = replace(strformat, "%j", datepart("y", strdate), 1, -1, vbbinarycompare)
' insert long year (4 digit)
strformat = replace(strformat, "%y", datepart("yyyy", strdate), 1, -1, vbbinarycompare)
' insert short year (2 digit)
strformat = replace(strformat, "%y", right(datepart("yyyy", strdate), 2), 1, -1, vbbinarycompare)
' insert weekday as integer (eg 0 = sunday)
strformat = replace(strformat, "%w", datepart("w", strdate, 1), 1, -1, vbbinarycompare)
' insert abbreviated weekday name (eg sun)
strformat = replace(strformat, "%a", weekdayname(datepart("w", strdate, 1), true), 1, -1, vbbinarycompare)
' insert non-abbreviated weekday name
strformat = replace(strformat, "%a", weekdayname(datepart("w", strdate, 1), false), 1, -1, vbbinarycompare)
' insert hour in 24hr format
str24hourpart = datepart("h", strdate)
if len(str24hourpart) < 2 then str24hourpart = "0" & str24hourpart
strformat = replace(strformat, "%h", str24hourpart, 1, -1, vbbinarycompare)
' insert hour in 12hr format
int12hourpart = datepart("h", strdate) mod 12
if int12hourpart = 0 then int12hourpart = 12
strformat = replace(strformat, "%h", int12hourpart, 1, -1, vbbinarycompare)
' insert minutes
strminutepart = datepart("n", strdate)
if len(strminutepart) < 2 then strminutepart = "0" & strminutepart
strformat = replace(strformat, "%n", strminutepart, 1, -1, vbbinarycompare)
' insert optional minutes
if cint(strminutepart) = 0 then
strformat = replace(strformat, "%n", "", 1, -1, vbbinarycompare)
else
if cint(strminutepart) < 10 then strminutepart = "0" & strminutepart
strminutepart = ":" & strminutepart
strformat = replace(strformat, "%n", strminutepart, 1, -1, vbbinarycompare)
end if
' insert seconds
strsecondpart = datepart("s", strdate)
if len(strsecondpart) < 2 then strsecondpart = "0" & strsecondpart
strformat = replace(strformat, "%s", strsecondpart, 1, -1, vbbinarycompare)
' insert am/pm indicator
if datepart("h", strdate) >= 12 then
strampm = "pm"
else
strampm = "am"
end if
strformat = replace(strformat, "%p", strampm, 1, -1, vbbinarycompare)
formatdate = strformat
end function
function getdayordinal( _
byval intday _
)
' accepts a day of the month
' as an integer and returns the
' appropriate suffix
on error resume next
dim strord
select case intday
case 1, 21, 31
strord = "st"
case 2, 22
strord = "nd"
case 3, 23
strord = "rd"
case else
strord = "th"
end select
getdayordinal = strord
end function
%>
<%
dim db
db = "dbms.mdb"
'******************************************************************
'执行sql语句,不返回值,sql语句最好是如下:
'update 表名 set 字段名=value,字段名=value where 字段名=value
'delete from 表名 where 字段名=value
'insert into 表名 (字段名,字段名) values (value,value)
'******************************************************************
sub noresult(sql)
dim conn
dim connstr
set conn = server.createobject("adodb.connection")
connstr = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(""&db&"")
conn.open connstr
conn.execute sql
conn.close
set conn = nothing
end sub
'*******************************************************************
'执行select语句,返回recordset对象。该对象只读。也就是不能更新
'*******************************************************************
function result(sql)
dim conn
dim connstr
dim rcs
set conn = server.createobject("adodb.connection")
connstr = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(""&db&"")
conn.open connstr
set rcs = server.createobject("adodb.recordset")
rcs.open sql, conn, 1, 1
set result = rcs
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
'*******************************************************************
' 把html标记替换
'*******************************************************************
function htmlencode2(str)
dim result
dim l
if isnull(str) then
htmlencode2 = ""
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)
result = result + "<br>"
case chr(34)
result = result + """%>
<%
cleft(string, length) 返回指定数目的从字符串的左边算起的字符,区分单双字节。
如:
dim mystring, leftstring
mystring = "文字测试vbscript"
leftstring = cleft(mystring, 10)
返回 "文字测试vb"。
myrandc(n) 生成随机字符,n为字符的个数
如:
response.write myrandn(10)
输出10个随机字符
myrandn(n) 生成随机数字,n为数字的个数
如:
response.write myrandn(10)
输出10个随机数字
formatquerystr(str) 格式化sql中的like字符串.
如:
q = request("q")
q = formatquerystr(q)
sql = "select * from [table] where aa like '%"& q &"%'"
getrnd(min, max) 返回min - max之间的一个随机数
如:
response.write getrnd(100, 200)
输出大于100到200之间的一个随机数
function cleft(str, n)
dim str1, str2, alln, islefted
str2 = ""
alln = 0
str1 = str
islefted = false
if isnull(str) then
cleft = ""
exit function
end if
for i = 1 to len(str1)
nowstr = mid(str1, i, 1)
if asc(nowstr)<0 then
alln = alln + 2
else
alln = alln + 1
end if
if (alln<= n) then
str2 = str2 & nowstr
else
islefted = true
exit for
end if
next
if islefted then
str2 = str2 & ".."
end if
cleft = str2
end function
function myrandc(n) '生成随机字符,n为字符的个数
dim thechr
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
function myrandn(n) '生成随机数字,n为数字的个数
dim thechr
thechr = ""
for i = 1 to n
dim znum, znum2
randomize
znum = cint(9 * rnd)
znum = znum + 48
thechr = thechr & chr(znum)
next
myrandn = thechr
end function
function formatquerystr(str) '格式化sql中的like字符串
dim nstr
nstr = str
nstr = replace(nstr, chr(0), "")
nstr = replace(nstr, "'", "''")
nstr = replace(nstr, "[", "[[]")
nstr = replace(nstr, "%", "[%]")
formatquerystr = nstr
end function
function getrnd(min, max)
randomize
getrnd = int((max - min + 1) * rnd + min)
end function
'*******************************************************************
'取得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
'*******************************************************************
'转换ip地址
'*******************************************************************
function cip(sip)
tip = cstr(sip)
sip1 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip2 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip3 = left(tip, cint(instr(tip, ".") -1))
sip4 = mid(tip, cint(instr(tip, ".") + 1))
cip = cint(sip1) * 256 * 256 * 256 + cint(sip2) * 256 * 256 + cint(sip3) * 256 + cint(sip4)
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, ">", ">")
fstring = replace(fstring, "<", "<")
fstring = replace(fstring, chr(32), " ")
fstring = replace(fstring, chr(9), " ")
fstring = replace(fstring, chr(34), """)
fstring = replace(fstring, chr(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
%>
<%
cleft(string, length) 返回指定数目的从字符串的左边算起的字符,区分单双字节。
如:
dim mystring, leftstring
mystring = "文字测试vbscript"
leftstring = cleft(mystring, 10)
返回 "文字测试vb"。
myrandc(n) 生成随机字符,n为字符的个数
如:
response.write myrandn(10)
输出10个随机字符
myrandn(n) 生成随机数字,n为数字的个数
如:
response.write myrandn(10)
输出10个随机数字
formatquerystr(str) 格式化sql中的like字符串.
如:
q = request("q")
q = formatquerystr(q)
sql = "select * from [table] where aa like '%"& q &"%'"
getrnd(min, max) 返回min - max之间的一个随机数
如:
response.write getrnd(100, 200)
输出大于100到200之间的一个随机数
function cleft(str, n)
dim str1, str2, alln, islefted
str2 = ""
alln = 0
str1 = str
islefted = false
if isnull(str) then
cleft = ""
exit function
end if
for i = 1 to len(str1)
nowstr = mid(str1, i, 1)
if asc(nowstr)<0 then
alln = alln + 2
else
alln = alln + 1
end if
if (alln<= n) then
str2 = str2 & nowstr
else
islefted = true
exit for
end if
next
if islefted then
str2 = str2 & ".."
end if
cleft = str2
end function
function myrandc(n) '生成随机字符,n为字符的个数
dim thechr
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
function myrandn(n) '生成随机数字,n为数字的个数
dim thechr
thechr = ""
for i = 1 to n
dim znum, znum2
randomize
znum = cint(9 * rnd)
znum = znum + 48
thechr = thechr & chr(znum)
next
myrandn = thechr
end function
function formatquerystr(str) '格式化sql中的like字符串
dim nstr
nstr = str
nstr = replace(nstr, chr(0), "")
nstr = replace(nstr, "'", "''")
nstr = replace(nstr, "[", "[[]")
nstr = replace(nstr, "%", "[%]")
formatquerystr = nstr
end function
function getrnd(min, max)
randomize
getrnd = int((max - min + 1) * rnd + min)
end function
'*******************************************************************
'取得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
'*******************************************************************
'转换ip地址
'*******************************************************************
function cip(sip)
tip = cstr(sip)
sip1 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip2 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip3 = left(tip, cint(instr(tip, ".") -1))
sip4 = mid(tip, cint(instr(tip, ".") + 1))
cip = cint(sip1) * 256 * 256 * 256 + cint(sip2) * 256 * 256 + cint(sip3) * 256 + cint(sip4)
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, ">", ">")
fstring = replace(fstring, "<", "<")
fstring = replace(fstring, chr(32), " ")
fstring = replace(fstring, chr(9), " ")
fstring = replace(fstring, chr(34), """)
fstring = replace(fstring, chr(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
%>
11.access数据库连接:
<%
option explicit
dim startime, endtime, conn, connstr, db
startime = timer()
'更改数据库名字
db = "data/dvbbs5.mdb"
set conn = server.createobject("adodb.connection")
connstr = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(db)
'如果你的服务器采用较老版本access驱动,请用下面连接方法
'connstr="driver={microsoft access driver (*.mdb)};dbq=" & server.mappath(db)
conn.open connstr
function closedatabase
conn.close
set conn = nothing
end function
%>
12.sql数据库连接:
<%
option explicit
dim startime, endtime, conn, connstr, db
startime = timer()
connstr = "driver={sql server};server=hudenq-n11t33nb;uid=sa;pwd=xsfeihu;database=dvbbs"
set conn = server.createobject("adodb.connection")
conn.open connstr
function closedatabase
conn.close
set conn = nothing
end function
%>
13.用键盘打开网页代码:
<script language="javascript">
function ctlent(eventobject)
{
if((event.ctrlkey && window.event.keycode==13)||(event.altkey && window.event.keycode==83))
{
window.open('网址','','')
}
}
</script>
这里是ctrl+enter和alt+s的代码 自己查下键盘的ascii码再换就行
14.让层不被控件复盖代码:
<div z-index:2><object ***></object></div> # 前面
<div z-index:1><object ***></object></div> # 后面
<div id="layer2" style="position:absolute; top:40;width:400px; height:95px;z-index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%></td></tr></table><iframe width=0 height=0></iframe></div>
<div id="layer1" style="position:absolute; top:50;width:200px; height:115px;z-index:1"><iframe height=100% width=100%></iframe></div>
15.动网flash广告代码:
<object classid="clsid27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="468" height="60"><param name=movie value="images/yj16d.swf"><param name=quality value=high><embed src="images/dvbanner.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash";;; type="application/x-shockwave-flash" width="468" height="60"></embed></object>
16.vbs弹出窗口小代码:
<script language=vbscript>
msgbox"你还没有注册或登陆论坛","0","精品论坛"
location.href = "login.asp"
</script>
16.使用fso修改文件特定内容的函数
<%
function fsochange(filename, target, string)
dim objfso, objcountfile, filetempdata
set objfso = server.createobject("scripting.filesystemobject")
set objcountfile = objfso.opentextfile(server.mappath(filename), 1, true)
filetempdata = objcountfile.readall
objcountfile.close
filetempdata = replace(filetempdata, target, string)
set objcountfile = objfso.createtextfile(server.mappath(filename), true)
objcountfile.write filetempdata
objcountfile.close
set objcountfile = nothing
set objfso = nothing
end function
%>
17.使用fso读取文件内容的函数
<%
function fsofileread(filename)
dim objfso, objcountfile, filetempdata
set objfso = server.createobject("scripting.filesystemobject")
set objcountfile = objfso.opentextfile(server.mappath(filename), 1, true)
fsofileread = objcountfile.readall
objcountfile.close
set objcountfile = nothing
set objfso = nothing
end function
%>
18.使用fso读取文件某一行的函数
<%
function fsolinedit(filename, linenum)
if linenum < 1 then exit function
dim fso, f, temparray, tempcnt
set fso = server.createobject("scripting.filesystemobject")
if not fso.fileexists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename), 1)
if not f.atendofstream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt, chr(13)&chr(10))
if linenum>ubound(temparray) + 1 then
exit function
else
fsolinedit = temparray(linenum -1)
end if
end if
end function
%>
19.使用fso写文件某一行的函数
<%
function fsolinewrite(filename, linenum, linecontent)
if linenum < 1 then exit function
dim fso, f, temparray, tempcnt
set fso = server.createobject("scripting.filesystemobject")
if not fso.fileexists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename), 1)
if not f.atendofstream then
tempcnt = f.readall
f.close
temparray = split(tempcnt, chr(13)&chr(10))
if linenum>ubound(temparray) + 1 then
exit function
else
temparray(linenum -1) = linecontent
end if
tempcnt = join(temparray, chr(13)&chr(10))
set f = fso.createtextfile(server.mappath(filename), true)
f.write tempcnt
end if
f.close
set f = nothing
end function
%>
20.使用fso添加文件新行的函数
<%
function fsoappline(filename, linecontent)
dim fso, f
set fso = server.createobject("scripting.filesystemobject")
if not fso.fileexists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename), 8, 1)
f.write chr(13)&chr(10)&linecontent
f.close
set f = nothing
end function
%>
21.读文件最后一行的函数
<%
function fsolastline(filename)
dim fso, f, temparray, tempcnt
set fso = server.createobject("scripting.filesystemobject")
if not fso.fileexists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename), 1)
if not f.atendofstream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt, chr(13)&chr(10))
fsolastline = temparray(ubound(temparray))
end if
end function
%>
利用fso取得bmp,jpg,png,gif文件信息(大小,宽、高等)
<%
'::: bmp, gif, jpg and png :::
'::: this function gets a specified number of bytes from any :::
'::: file, starting at the offset (base 1) :::
'::: :::
'::: passed: :::
'::: flnm => filespec of file to read :::
'::: offset => offset at which to start reading :::
'::: bytes => how many bytes to read :::
'::: :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function getbytes(flnm, offset, bytes)
dim objfso
dim objftemp
dim objtextstream
dim lngsize
on error resume next
set objfso = createobject("scripting.filesystemobject")
' first, we get the filesize
set objftemp = objfso.getfile(flnm)
lngsize = objftemp.size
set objftemp = nothing
fsoforreading = 1
set objtextstream = objfso.opentextfile(flnm, fsoforreading)
if offset > 0 then
strbuff = objtextstream.read(offset - 1)
end if
if bytes = -1 then ' get all!
getbytes = objtextstream.read(lngsize) 'readall
else
getbytes = objtextstream.read(bytes)
end if
objtextstream.close
set objtextstream = nothing
set objfso = nothing
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: :::
'::: functions to convert two bytes to a numeric value (long) :::
'::: (both little-endian and big-endian) :::
'::: :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function lngconvert(strtemp)
lngconvert = clng(asc(left(strtemp, 1)) + ((asc(right(strtemp, 1)) * 256)))
end function
function lngconvert2(strtemp)
lngconvert2 = clng(asc(right(strtemp, 1)) + ((asc(left(strtemp, 1)) * 256)))
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: :::
'::: this function does most of the real work. it will attempt :::
'::: to read any file, regardless of the extension, and will :::
'::: identify if it is a graphical image. :::
'::: :::
'::: passed: :::
'::: flnm => filespec of file to read :::
'::: width => width of image :::
'::: height => height of image :::
'::: depth => color depth (in number of colors) :::
'::: strimagetype=> type of image (e.g. gif, bmp, etc.) :::
'::: :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function gfxspex(flnm, width, height, depth, strimagetype)
dim strpng
dim strgif
dim strbmp
dim strtype
strtype = ""
strimagetype = "(unknown)"
gfxspex = false
strpng = chr(137) & chr(80) & chr(78)
strgif = "gif"
strbmp = chr(66) & chr(77)
strtype = getbytes(flnm, 0, 3)
if strtype = strgif then ' is gif
strimagetype = "gif"
width = lngconvert(getbytes(flnm, 7, 2))
height = lngconvert(getbytes(flnm, 9, 2))
depth = 2 ^ ((asc(getbytes(flnm, 11, 1)) and 7) + 1)
gfxspex = true
elseif left(strtype, 2) = strbmp then ' is bmp
strimagetype = "bmp"
width = lngconvert(getbytes(flnm, 19, 2))
height = lngconvert(getbytes(flnm, 23, 2))
depth = 2 ^ (asc(getbytes(flnm, 29, 1)))
gfxspex = true
elseif strtype = strpng then ' is png
strimagetype = "png"
width = lngconvert2(getbytes(flnm, 19, 2))
height = lngconvert2(getbytes(flnm, 23, 2))
depth = getbytes(flnm, 25, 2)
select case asc(right(depth, 1))
case 0
depth = 2 ^ (asc(left(depth, 1)))
gfxspex = true
case 2
depth = 2 ^ (asc(left(depth, 1)) * 3)
gfxspex = true
case 3
depth = 2 ^ (asc(left(depth, 1))) '8
gfxspex = true
case 4
depth = 2 ^ (asc(left(depth, 1)) * 2)
gfxspex = true
case 6
depth = 2 ^ (asc(left(depth, 1)) * 4)
gfxspex = true
case else
depth = -1
end select
else
strbuff = getbytes(flnm, 0, -1) ' get all bytes from file
lngsize = len(strbuff)
flgfound = 0
strtarget = chr(255) & chr(216) & chr(255)
flgfound = instr(strbuff, strtarget)
if flgfound = 0 then
exit function
end if
strimagetype = "jpg"
lngpos = flgfound + 2
exitloop = false
do while exitloop = false and lngpos < lngsize
do while asc(mid(strbuff, lngpos, 1)) = 255 and lngpos < lngsize
lngpos = lngpos + 1
loop
if asc(mid(strbuff, lngpos, 1)) < 192 or asc(mid(strbuff, lngpos, 1)) > 195 then
lngmarkersize = lngconvert2(mid(strbuff, lngpos + 1, 2))
lngpos = lngpos + lngmarkersize + 1
else
exitloop = true
end if
loop
'
if exitloop = false then
width = -1
height = -1
depth = -1
else
height = lngconvert2(mid(strbuff, lngpos + 4, 2))
width = lngconvert2(mid(strbuff, lngpos + 6, 2))
depth = 2 ^ (asc(mid(strbuff, lngpos + 8, 1)) * 8)
gfxspex = true
end if
end if
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: test harness :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' to test, we'll just try to show all files with a .gif extension in the root of c:
set objfso = createobject("scripting.filesystemobject")
set objf = objfso.getfolder("c:\")
set objfc = objf.files
response.write "<table border=""0"" cellpadding=""5"">"
for each f1 in objfc
if instr(ucase(f1.name), ".gif") then
response.write "<tr><td>" & f1.name & "</td><td>" & f1.datecreated & "</td><td>" & f1.size & "</td><td>"
if gfxspex(f1.path, w, h, c, strtype) = true then
response.write w & " x " & h & " " & c & " colors"
else
response.write " "
end if
response.write "</td></tr>"
end if
next
response.write "</table>"
set objfc = nothing
set objf = nothing
set objfso = nothing
%>
24.点击返回上页代码:
<form>
<p><input type="button" value="返回上一步" onclick="history.back(-1)"></p>
</form>
24.点击刷新代码:
<form>
<p><input type="button" value="刷新按钮一" onclick="reloadbutton()"></p>
</form>
<script language="javascript"><!--
function reloadbutton(){location.href="allbutton.htm";}
// --></script>
24.点击刷新代码2:
<form>
<p><input type="button" value="刷新按钮二" onclick="history.go(0)"> </p>
</form>
<form>
<p><input type="button" value="打开一个网站" onclick="homebutton()"></p>
</form>
<script language="javascript"><!--
function homebutton(){location.href="http://nettrain.126.com";;;}
// --></script>
25.弹出警告框代码:
<form>
<p><input type="button" value="弹出警告框" onclick="alertbutton()"></p>
</form>
<script language="javascript"><!--
function alertbutton(){window.alert("要多多光临呀!");}
// --></script>
26.状态栏信息
<form>
<p><input type="button" value="状态栏信息" onclick="statusbutton()"></p>
</form>
<script language="javascript"><!--
function statusbutton(){window.status="要多多光临呀!";}
// --></script>
27.背景色变换
<form>
<p><input type="button" value="背景色变换" onclick="bgbutton()"></p>
</form>
<script>function bgbutton(){
if (document.bgcolor=='#00ffff')
{document.bgcolor='#ffffff';}
else{document.bgcolor='#00ffff';}
}
</script>
28.点击打开新窗口
<form>
<p><input type="button" value="打开新窗口" onclick="newwindow()"></p>
</form>
<script language="javascript"><!--
function newwindow(){window.open("http://www.mcmx.com";;,"","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");}
// --></script></body>
29.分页代码:
<%''本程序文件名为:pages.asp%>
<%''包含ado常量表文件adovbs.inc,可从"\program files\common files\system\ado"目录下拷贝%>
<!--#include file="adovbs.inc"-->
<%''*建立数据库连接,这里是oracle8.05数据库
set conn = server.createobject("adodb.connection")
conn.open "provider=msdaora.1;data source=yoursrcname;user id=youruserid;password=yourpassword;"
set rs = server.createobject("adodb.recordset") ''创建recordset对象
rs.cursorlocation = aduseclient ''设定记录集指针属性
''*设定一页内的记录总数,可根据需要进行调整
rs.pagesize = 10
''*设置查询语句
strsql = "select id,姓名,住址,电话 from 通讯录 order by id"
rs.open strsql, conn, adopenstatic, adlockreadonly, adcmdtext
%>
<html>
<head>
<title>分页示例</title>
<script language=javascript>
//点击"[第一页]"时响应:
function pagefirst()
{
document.myform.currentpage.selectedindex=0;
document.myform.currentpage.onchange();
}
//点击"[上一页]"时响应:
function pageprior()
{
document.myform.currentpage.selectedindex--;
document.myform.currentpage.onchange();
}
//点击"[下一页]"时响应:
function pagenext()
{
document.myform.currentpage.selectedindex++;
document.myform.currentpage.onchange();
}
//点击"[最后一页]"时响应:
function pagelast()
{
document.myform.currentpage.selectedindex=document.myform.currentpage.length-1;
document.myform.currentpage.onchange();
}
//选择"第?页"时响应:
function pagecurrent()
{ //pages.asp是本程序的文件名
document.myform.action='pages.asp?page='+(document.myform.currentpage.selectedindex+1)
document.myform.submit();
}
</script>
</head>
<body bgcolor="#ffffcc" link="#008000" vlink="#008000" alink="#ff0000"">
<%
if rs.eof then
response.write("<font size=2 color=#000080>[数据库中没有记录!]</font>")
else
''指定当前页码
if request("currentpage") = "" then
rs.absolutepage = 1
else
rs.absolutepage = clng(request("currentpage"))
end if
''创建表单myform,方法为get
response.write("<form method=get name=myform>")
response.write("<p align=center><font size=2 color=#008000>")
''设置翻页超链接
if rs.pagecount = 1 then
response.write("[第一页] [上一页] [下一页] [最后一页] ")
else
if rs.absolutepage = 1 then
response.write("[第一页] [上一页] ")
response.write("[<a href=java script:pagenext()>下一页</a>] ")
response.write("[<a href=java script:pagelast()>最后一页</a>] ")
else
if rs.absolutepage = rs.pagecount then
response.write("[<a href=java script:pagefirst()>第一页</a>] ")
response.write("[<a href=java script:pageprior()>上一页</a>] ")
response.write("[下一页] [最后一页] ")
else
response.write("[<a href=java script:pagefirst()>第一页</a>] ")
response.write("[<a href=java script:pageprior()>上一页</a>] ")
response.write("[<a href=java script:pagenext()>下一页</a>] ")
response.write("[<a href=java script:pagelast()>最后一页</a>] ")
end if
end if
end if
''创建下拉列表框,用于选择浏览页码
response.write("第<select size=1 name=currentpage onchange=pagecurrent()>")
for i = 1 to rs.pagecount
if rs.absolutepage = i then
response.write("<option selected>"&i&"</option>") ''当前页码
else
response.write("<option>"&i&"</option>")
end if
next
response.write("</select>页/共"&rs.pagecount&"页 共"&rs.recordcount&"条记录</font><p>")
response.write("</form>")
''创建表格,用于显示
response.write("<table align=center cellspacing=1 cellpadding=1 border=1")
response.write(" bordercolor=#99ccff bordercolordark=#b0e0e6 bordercolorlight=#000066>")
response.write("<tr bgcolor=#ccccff bordercolor=#000066>")
set columns = rs.fields
''显示表头
for i = 0 to columns.count -1
response.write("<td align=center width=200 height=13>")
response.write("<font size=2><b>"&columns(i).name&"</b></font></td>")
next
response.write("</tr>")
''显示内容
for i = 1 to rs.pagesize
response.write("<tr bgcolor=#99ccff bordercolor=#000066>")
for j = 0 to columns.count -1
response.write("<td><font size=2>"&columns(j)&"</font></td>")
next
response.write("</tr>")
rs.movenext
if rs.eof then exit for
next
response.write("</table>")
end if
%>
</body>
</html>
<%
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
%>
<%
'定义超全局变量
dim urlself, uriself
uriself = request.servervariables("script_name")
if request.querystring = "" then
urlself = uriself
else
urlself = uriself & "?" & request.querystring
end if
response.charset = "gb2312"
response.buffer = true
response.expires = -1
'===================================================================================
' 函数原型:gotourl (url)
'功能:转到指定的url
'参数:url 要跳转的url
'返 回 值:无
'涉及的表:无
'===================================================================================
public function gotourl(url)
response.write "<script language=""javascript"">location.href='" & url & "';</script>"
end function
'===================================================================================
' 函数原型:messagebox (msg)
'功能:显示消息框
'参数:要显示的消息
'返 回 值:无
'涉及的表:无
'===================================================================================
public function messagebox(msg)
msg = replace(msg, "\", "\\")
msg = replace(msg, "'", "\'")
msg = replace(msg, """", "\""")
msg = replace(msg, vbcrlf, "\n")
msg = replace(msg, vbcr, "")
msg = replace(msg, vblf, "")
response.write "<script language=""javascript"">alert('" & msg & "');</script>"
end function
'===================================================================================
' 函数原型:returnvalue (bolvalue)
'功能:设置window对象的返回值:只能是布尔值
'参数:返回值
'返 回 值:无
'涉及的表:无
'===================================================================================
public function returnvalue(bolvalue)
if bolvalue then
response.write "<script language=""javascript"">window.returnvalue=true;</script>"
else
response.write "<script language=""javascript"">window.returnvalue=false;</script>"
end if
end function
'===================================================================================
' 函数原型:goback (url)
'功能:后退
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function goback()
response.write "<script language=""javascript"">history.go(-1);</script>"
end function
'===================================================================================
' 函数原型:closewindow ()
'功能:关闭窗口
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function closewindow()
response.write "<script language=""javascript"">window.opener=null;window.close();</script>"
end function
'===================================================================================
' 函数原型:refreshparent ()
'功能:刷新父框架
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function refreshparent()
response.write "<script language=""javascript"">if(parent!=self) parent.location.reload();</script>"
end function
'===================================================================================
' 函数原型:refreshtop ()
'功能:刷新*框架
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function refreshtop()
response.write "<script language=""javascript"">if(top!=self) top.location.reload();</script>"
end function
'===================================================================================
' 函数原型:genpassword (intlen,passmask)
'功能:生成随机密码
'参数:intlen新密码长度
'passmask生成密码的掩码默认为空
'返 回 值:无
'涉及的表:无
'===================================================================================
public function genpassword(intlen, passmask)
dim icnt, postemp
randomize
if passmask = "" then
passmask = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz"
end if
for icnt = 1 to intlen
postemp = fix(rnd(1) * (len(passmask))) + 1
genpassword = genpassword & mid(passmask, postemp, 1)
next
end function
'===================================================================================
' 函数原型:genserialstring ()
'功能:生成序列号
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function genserialstring()
genserialstring = year(now())
if month(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & month(now())
if day(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & day(now())
if hour(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & hour(now())
if minute(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & minute(now())
if second(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & second(now())
genserialstring = genserialstring & genpassword(6, "0123456789abcdefghijklmnopqrstuvwxyz")
end function
'===================================================================================
' 函数原型:changepage(urltemplete,pageindex)
'功能:根据url模板生成新的页面url
'参数:urltempleteurl模板
' pageindex新的页码
'返 回 值:生成的url
'涉及的表:无
'===================================================================================
public function changepage(urltemplete, pageindex)
changepage = setquerystring(urltemplete, "page", pageindex)
end function
'===================================================================================
' 函数原型:buildpath(spath)
'功能:根据指定的路径创建目录
'参数:spathurl模板
'返 回 值:如果成功,返回空字符串,否则返回错误信息和错误位置
'涉及的表:无
'===================================================================================
public function buildpath (spath)
dim icnt
dim path
dim basepath
path = split(spath, "/")
if left(spath, 1) = "/" or left(spath, 1) = "\" then
basepath = server.mappath("/")
else
basepath = server.mappath(".")
end if
dim cpath, ofso
cpath = basepath
buildpath = ""
set ofso = server.createobject("scripting.filesystemobject")
for icnt = lbound(path) to ubound(path)
if trim(path(icnt))<>"" then
cpath = cpath & "\" & trim(path(icnt))
if not ofso.folderexists(cpath) then
on error resume next
ofso.createfolder cpath
if err.number<>0 then
buildpath = err.description & "[" & cpath & "]"
exit for
end if
on error goto 0
end if
end if
next
set ofso = nothing
end function
'===================================================================================
' 函数原型:getuseragentinfo(byref vsoft,byref vos)
'功能:获取客户端操作系统和浏览器信息
'参数:vsoft浏览器信息
'vos操作系统信息
'返 回 值:无
'涉及的表:无
'===================================================================================
public function getuseragentinfo(byref vsoft, byref vos)
dim thesoft
thesoft = request.servervariables("http_user_agent")
' 浏览器
if instr(thesoft, "netcaptor") then
vsoft = "netcaptor"
elseif instr(thesoft, "msie 6") then
vsoft = "msie 6.0"
elseif instr(thesoft, "msie 5.5+") then
vsoft = "msie 5.5"
elseif instr(thesoft, "msie 5") then
vsoft = "msie 5.0"
elseif instr(thesoft, "msie 4") then
vsoft = "msie 4.0"
elseif instr(thesoft, "netscape") then
vsoft = "netscape"
elseif instr(thesoft, "opera") then
vsoft = "opera"
else
vsoft = "other"
end if
' 操作系统
if instr(thesoft, "windows nt 5.0") then
vos = "windows 2000"
elseif instr(thesoft, "windows nt 5.1") then
vos = "windows xp"
elseif instr(thesoft, "windows nt 5.2") then
vos = "windows 2003"
elseif instr(thesoft, "windows nt") then
vos = "windows nt"
elseif instr(thesoft, "windows 9") then
vos = "windows 9x"
elseif instr(thesoft, "unix") then
vos = "unix"
elseif instr(thesoft, "linux") then
vos = "linux"
elseif instr(thesoft, "sunos") then
vos = "sunos"
elseif instr(thesoft, "bsd") then
vos = "bsd"
elseif instr(thesoft, "mac") then
vos = "mac"
else
vos = "other"
end if
end function
'===================================================================================
' 函数原型:getregexpobject()
'功能:获得一个正则表达式对象
'参数:无
'返 回 值:正则表达式对象
'涉及的表:无
'===================================================================================
public function getregexpobject(spattern)
dim r
set r = new regexp
r.global = true
r.ignorecase = true
r.multiline = true
r.pattern = spattern
set getregexpobject = r
set r = nothing
end function
'===================================================================================
' 函数原型:regexptest(pattern,string)
'功能:正则表达式检测
'参数:pattern模式字符串
'string待检查的字符串
'返 回 值:是否匹配
'涉及的表:无
'===================================================================================
public function regexptest(p, s)
dim r
set r = getregexpobject(p)
regexptest = r.test(s)
set r = nothing
end function
'===================================================================================
' 函数原型:regexpreplace(ssource,spattern,srep)
'功能:正则表达式替换
'参数:ssource要替换的源字符串
'spattern模式字符串
'srep要替换的目标字符串
'返 回 值:替换后的字符串
'涉及的表:无
'===================================================================================
public function regexpreplace(ssource, spattern, srep)
dim r
set r = getregexptest(spattern)
regexpreplace = r.replace(ssource, srep)
set r = nothing
end function
'===================================================================================
' 函数原型:createxmlparser()
'功能:创建一个尽可能高版本的xmldom
'参数:无
'返 回 值:idomdocument对象
'涉及的表:无
'===================================================================================
public function createxmlparser()
on error resume next
set createxmlparser = server.createobject("msxml2.domdocument.4.0")
if err.number<>0 then
err.clear
set createxmlparser = server.createobject("msxml2.domdocument.3.0")
if err.number<>0 then
err.clear
set createxmlparser = server.createobject("msxml2.domdocument.2.6")
if err.number<>0 then
err.clear
set createxmlparser = server.createobject("msxml2.domdocument")
if err.number<>0 then
err.clear
set createxmlparser = server.createobject("microsoft.xmldom")
if err.number<>0 then
err.clear
set createxmlparser = nothing
else
exit function
end if
else
exit function
end if
else
exit function
end if
else
exit function
end if
else
exit function
end if
on error goto 0
end function
'===================================================================================
' 函数原型:createhttpposter()
'功能:创建一个尽可能高版本的xmlhttp
'参数:serverorclient创建serverxmlhttp还是xmlhttp
'返 回 值:ixmlhttp对象
'涉及的表:无
'===================================================================================
public function createhttpposter(soc)
dim s
if soc then
s = "serverxmlhttp"
else
s = "xmlhttp"
end if
on error resume next
set createhttpposter = server.createobject("msxml2." & s & ".4.0")
if err.number<>0 then
err.clear
set createhttpposter = server.createobject("msxml2." & s & ".3.0")
if err.number<>0 then
err.clear
set createhttpposter = server.createobject("msxml2." & s)
if err.number<>0 then
set createhttpposter = nothing
else
exit function
end if
else
exit function
end if
else
exit function
end if
on error goto 0
end function
'===================================================================================
' 函数原型:xmlthrowerror (errcode,errreason)
'功能:抛出一个xml错误消息
'参数:errcode错误编码
'errreason错误原因
'返 回 值:无
'涉及的表:无
'===================================================================================
public sub xmlthrowerror (errcode, errreason)
response.clear
response.contenttype = "text/xml"
response.write"<?xml version=""1.0"" encoding=""gb2312"" standalone=""yes"" ?>" & vbcrlf & _
"<error code=""" & errcode & """ reason=""" & errreason & """ />" & vbcrlf
response.flush
response.end
end sub
'===================================================================================
' 函数原型:getxmlnodevalue(byref xmldom,sfilter,sdefvalue)
'功能:从一个xml文档中查找指定节点的值
'参数:xmldomxml文档
'sfilterxpath定位字符串
'sdefvalue默认值
'返 回 值:无
'涉及的表:无
'===================================================================================
public function getxmlnodevalue(byref xmldom, sfilter, sdefvalue)
dim onode
set onode = xmldom.selectsinglenode(sfilter)
if typename(onode) = "nothing" or typename(onode) = "null" or typename(onode) = "empty" then
getxmlnodevalue = sdefvalue
set onode = nothing
else
getxmlnodevalue = trim(onode.text)
set onode = nothing
end if
end function
'===================================================================================
' 函数原型:getxmlnodeattribute(byref xmldom,sfilter,sname,sdefvalue)
'功能:从一个xml文档中查找指定节点的指定属性
'参数:xmldomxml文档
'sfilterxpath定位字符串
'sname要查询的属性名称
'sdefvalue默认值
'返 回 值:无
'涉及的表:无
'===================================================================================
public function getxmlnodeattribute(byref xmldom, sfilter, sname, sdefvalue)
dim onode
set onode = xmldom.selectsinglenode(sfilter)
if typename(onode) = "nothing" or typename(onode) = "null" or typename(onode) = "empty" then
getxmlnodeattribute = sdefvalue
set onode = nothing
else
dim ptemp
set ptemp = onode.getattribute(sname)
if typename(ptemp) = "nothing" or typename(ptemp) = "null" or typename(ptemp) = "empty" then
getxmlnodeattribute = sdefvalue
set onode = nothing
set ptemp = nothing
else
getxmlnodeattribute = trim(ptemp.value)
set onode = nothing
set ptemp = nothing
end if
end if
end function
'===================================================================================
' 函数原型:getquerystringnumber (fieldname,defvalue)
'功能:从querystring获取一个整数
'参数:fieldname参数名
'defvalue默认值
'返 回 值:无
'涉及的表:无
'===================================================================================
public function getquerystringnumber (fieldname, defvalue)
dim r
r = request.querystring(fieldname)
if r = "" then
getquerystringnumber = defvalue
exit function
else
if not isnumeric(r) then
getquerystringnumber = defvalue
exit function
else
on error resume next
r = cdbl(r)
if err.number<>0 then
err.clear
getquerystringnumber = defvalue
exit function
else
getquerystringnumber = r
end if
on error goto 0
end if
end if
end function
'===================================================================================
' 函数原型:iif (testexpr,value1,value2)
'功能:相当于c/c++里面的 ?: 运算符
'参数:testexprboolean表达式
'value1testexpr=true 时的取值
'value2testexpr=false 时的取值
'返 回 值:如果testexpr为true返回value1否则返回value2
'涉及的表:无
'说明:vbscript里没有iif函数
'===================================================================================
public function iif(testexpr, value1, value2)
if testexpr = true then
iif = value1
else
iif = value2
end if
end function
'===================================================================================
' 函数原型:urlencoding (v,f)
'功能:url编码函数
'参数:v中英文混合字符串
'f是否对ascii字符编码
'返 回 值:编码后的asc字符串
'涉及的表:无
'===================================================================================
public function urlencoding(v, f)
dim s, t, i, j, h, l, x
s = ""
x = len(v)
for i = 1 to x
t = mid(v, i, 1)
j = asc(t)
if j> 0 then
if f then
s = s & "%" & right("00" & hex(asc(t)), 2)
else
s = s & t
end if
else
if j < 0 then j = j + &h10000
h = (j and &hff00) \ &hff
l = j and &hff
s = s & "%" & hex(h) & "%" & hex(l)
end if
next
urlencoding = s
end function
'===================================================================================
' 函数原型:urldecoding (sin)
'功能:url解码码函数
'参数:vurl编码的字符串
'返 回 值:解码后的字符串
'涉及的表:无
'===================================================================================
public function urldecoding(sin)
dim s, i, l, c, t, n
s = ""
l = len(sin)
for i = 1 to l
c = mid(sin, i, 1)
if c<>"%" then
s = s & c
else
c = mid(sin, i + 1, 2)
i = i + 2
t = cint("&h" & c)
if t<&h80 then
s = s & chr(t)
else
c = mid(sin, i + 1, 3)
if left(c, 1)<>"%" then
urldecoding = s
exit function
else
c = right(c, 2)
n = cint("&h" & c)
t = t * 256 + n -65536
s = s & chr(t)
i = i + 3
end if
end if
end if
next
urldecoding = s
end function
'===================================================================================
' 函数原型:bytes2bstr (v)
'功能:utf-8编码转换到正常的gb2312
'参数:vutf-8编码字节流
'返 回 值:解码后的字符串
'涉及的表:无
'===================================================================================
public function bytes2bstr(v)
dim r, i, t, n
r = ""
for i = 1 to lenb(v)
t = ascb(midb(v, i, 1))
if t < &h80 then
r = r & chr(t)
else
n = ascb(midb(v, i + 1, 1))
r = r & chr(clng(t) * &h100 + cint(n))
i = i + 1
end if
next
bytes2bstr = r
end function
%>
'*******************************************************************
'取得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
'*******************************************************************
'转换ip地址
'*******************************************************************
function cip(sip)
tip = cstr(sip)
sip1 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip2 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip3 = left(tip, cint(instr(tip, ".") -1))
sip4 = mid(tip, cint(instr(tip, ".") + 1))
cip = cint(sip1) * 256 * 256 * 256 + cint(sip2) * 256 * 256 + cint(sip3) * 256 + cint(sip4)
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
'*******************************************************************
' 我比较喜欢将以上三个结合起来使用
'*******************************************************************
function alert(message, gourl)
message = replace(message, "'", "\'")
if gourl = "-1" then
response.write ("<script language=javascript>alert('" & message & "');history.go(-1)</script>")
else
response.write ("<script language=javascript>alert('" & message & "');location='" & gourl &"'</script>")
end if
response.end()
end function
'*******************************************************************
' 指定秒数重定向另外的连接
'*******************************************************************
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, ">", ">")
fstring = replace(fstring, "<", "<")
fstring = replace(fstring, chr(32), " ")
fstring = replace(fstring, chr(9), " ")
fstring = replace(fstring, chr(34), """)
fstring = replace(fstring, chr(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
%>
<%
1.检查是否有效邮件地址
function checkemail(stremail)
dim re
set re = new regexp
re.pattern = "^[w-.]{1,}@([da-za-z-]{1,}.){1,}[da-za-z-]{2,3}$"
re.ignorecase = true
checkemail = re.test(stremail)
end function
2.测试变量是否为空值,空值的含义包括:变量不存在 / 为空,对象为nothing,0,空数组,字符串为空
function isblank(byref var)
isblank = false
select case true
case isobject(var)
if var is nothing then isblank = true
case isempty(var), isnull(var)
isblank = true
case isarray(var)
if ubound(var) = 0 then isblank = true
case isnumeric(var)
if (var = 0) then isblank = true
case else
if trim(var) = "" then isblank = true
end select
end function
3.得到浏览器目前的url
function getcururl()
if request.servervariables("https") = "on" then
getcurrenturl = "https://"
else
getcurrenturl = "http://"
end if
getcururl = getcururl & request.servervariables("server_name")
if (request.servervariables("server_port") <> 80) then getcururl = getcururl & ":" & request.servervariables("server_port")
getcururl = getcururl & request.servervariables("url")
if (request.querystring <> "") then getcururl = getcururl & "?" & request.querystring
end function
4.md5加密函数
private const bits_to_a_byte = 8
private const bytes_to_a_word = 4
private const bits_to_a_word = 32
private m_lonbits(30)
private m_l2power(30)
m_lonbits(0) = clng(1)
m_lonbits(1) = clng(3)
m_lonbits(2) = clng(7)
m_lonbits(3) = clng(15)
m_lonbits(4) = clng(31)
m_lonbits(5) = clng(63)
m_lonbits(6) = clng(127)
m_lonbits(7) = clng(255)
m_lonbits(8) = clng(511)
m_lonbits(9) = clng(1023)
m_lonbits(10) = clng(2047)
m_lonbits(11) = clng(4095)
m_lonbits(12) = clng(8191)
m_lonbits(13) = clng(16383)
m_lonbits(14) = clng(32767)
m_lonbits(15) = clng(65535)
m_lonbits(16) = clng(131071)
m_lonbits(17) = clng(262143)
m_lonbits(18) = clng(524287)
m_lonbits(19) = clng(1048575)
m_lonbits(20) = clng(2097151)
m_lonbits(21) = clng(4194303)
m_lonbits(22) = clng(8388607)
m_lonbits(23) = clng(16777215)
m_lonbits(24) = clng(33554431)
m_lonbits(25) = clng(67108863)
m_lonbits(26) = clng(134217727)
m_lonbits(27) = clng(268435455)
m_lonbits(28) = clng(536870911)
m_lonbits(29) = clng(1073741823)
m_lonbits(30) = clng(2147483647)
m_l2power(0) = clng(1)
m_l2power(1) = clng(2)
m_l2power(2) = clng(4)
m_l2power(3) = clng(8)
m_l2power(4) = clng(16)
m_l2power(5) = clng(32)
m_l2power(6) = clng(64)
m_l2power(7) = clng(128)
m_l2power(8) = clng(256)
m_l2power(9) = clng(512)
m_l2power(10) = clng(1024)
m_l2power(11) = clng(2048)
m_l2power(12) = clng(4096)
m_l2power(13) = clng(8192)
m_l2power(14) = clng(16384)
m_l2power(15) = clng(32768)
m_l2power(16) = clng(65536)
m_l2power(17) = clng(131072)
m_l2power(18) = clng(262144)
m_l2power(19) = clng(524288)
m_l2power(20) = clng(1048576)
m_l2power(21) = clng(2097152)
m_l2power(22) = clng(4194304)
m_l2power(23) = clng(8388608)
m_l2power(24) = clng(16777216)
m_l2power(25) = clng(33554432)
m_l2power(26) = clng(67108864)
m_l2power(27) = clng(134217728)
m_l2power(28) = clng(268435456)
m_l2power(29) = clng(536870912)
m_l2power(30) = clng(1073741824)
private function lshift(lvalue, ishiftbits)
if ishiftbits = 0 then
lshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and 1 then
lshift = &h80000000
else
lshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
if (lvalue and m_l2power(31 - ishiftbits)) then
lshift = ((lvalue and m_lonbits(31 - (ishiftbits + 1))) * m_l2power(ishiftbits)) or &h80000000
else
lshift = ((lvalue and m_lonbits(31 - ishiftbits)) * m_l2power(ishiftbits))
end if
end function
private function rshift(lvalue, ishiftbits)
if ishiftbits = 0 then
rshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and &h80000000 then
rshift = 1
else
rshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
rshift = (lvalue and &h7ffffffe) m_l2power(ishiftbits)
if (lvalue and &h80000000) then
rshift = (rshift or (&h40000000 m_l2power(ishiftbits - 1)))
end if
end function
private function rotateleft(lvalue, ishiftbits)
rotateleft = lshift(lvalue, ishiftbits) or rshift(lvalue, (32 - ishiftbits))
end function
private function addunsigned(lx, ly)
dim lx4
dim ly4
dim lx8
dim ly8
dim lresult
lx8 = lx and &h80000000
ly8 = ly and &h80000000
lx4 = lx and &h40000000
ly4 = ly and &h40000000
lresult = (lx and &h3fffffff) + (ly and &h3fffffff)
if lx4 and ly4 then
lresult = lresult xor &h80000000 xor lx8 xor ly8
elseif lx4 or ly4 then
if lresult and &h40000000 then
lresult = lresult xor &hc0000000 xor lx8 xor ly8
else
lresult = lresult xor &h40000000 xor lx8 xor ly8
end if
else
lresult = lresult xor lx8 xor ly8
end if
addunsigned = lresult
end function
private function f(x, y, z)
f = (x and y) or ((not x) and z)
end function
private function g(x, y, z)
g = (x and z) or (y and (not z))
end function
private function h(x, y, z)
h = (x xor y xor z)
end function
private function i(x, y, z)
i = (y xor (x or (not z)))
end function
private sub ff(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(f(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private sub gg(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(g(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private sub hh(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(h(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private sub ii(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(i(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private function converttowordarray(smessage)
dim lmessagelength
dim lnumberofwords
dim lwordarray()
dim lbyteposition
dim lbytecount
dim lwordcount
const modulus_bits = 512
const congruent_bits = 448
lmessagelength = len(smessage)
lnumberofwords = (((lmessagelength + ((modulus_bits - congruent_bits) bits_to_a_byte)) (modulus_bits bits_to_a_byte)) + 1) * (modulus_bits bits_to_a_word)
redim lwordarray(lnumberofwords - 1)
lbyteposition = 0
lbytecount = 0
do until lbytecount >= lmessagelength
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (lbytecount mod bytes_to_a_word) * bits_to_a_byte
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(asc(mid(smessage, lbytecount + 1, 1)), lbyteposition)
lbytecount = lbytecount + 1
loop
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (lbytecount mod bytes_to_a_word) * bits_to_a_byte
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(&h80, lbyteposition)
lwordarray(lnumberofwords - 2) = lshift(lmessagelength, 3)
lwordarray(lnumberofwords - 1) = rshift(lmessagelength, 29)
converttowordarray = lwordarray
end function
private function wordtohex(lvalue)
dim lbyte
dim lcount
for lcount = 0 to 3
lbyte = rshift(lvalue, lcount * bits_to_a_byte) and m_lonbits(bits_to_a_byte - 1)
wordtohex = wordtohex & right("0" & hex(lbyte), 2)
next
end function
public function md5(smessage)
dim x
dim k
dim aa
dim bb
dim cc
dim dd
dim a
dim b
dim c
dim d
const s11 = 7
const s12 = 12
const s13 = 17
const s14 = 22
const s21 = 5
const s22 = 9
const s23 = 14
const s24 = 20
const s31 = 4
const s32 = 11
const s33 = 16
const s34 = 23
const s41 = 6
const s42 = 10
const s43 = 15
const s44 = 21
x = converttowordarray(smessage)
a = &h67452301
b = &hefcdab89
c = &h98badcfe
d = &h10325476
for k = 0 to ubound(x) step 16
aa = a
bb = b
cc = c
dd = d
ff a, b, c, d, x(k + 0), s11, &hd76aa478
ff d, a, b, c, x(k + 1), s12, &he8c7b756
ff c, d, a, b, x(k + 2), s13, &h242070db
ff b, c, d, a, x(k + 3), s14, &hc1bdceee
ff a, b, c, d, x(k + 4), s11, &hf57c0faf
ff d, a, b, c, x(k + 5), s12, &h4787c62a
ff c, d, a, b, x(k + 6), s13, &ha8304613
ff b, c, d, a, x(k + 7), s14, &hfd469501
ff a, b, c, d, x(k + 8), s11, &h698098d8
ff d, a, b, c, x(k + 9), s12, &h8b44f7af
ff c, d, a, b, x(k + 10), s13, &hffff5bb1
ff b, c, d, a, x(k + 11), s14, &h895cd7be
ff a, b, c, d, x(k + 12), s11, &h6b901122
ff d, a, b, c, x(k + 13), s12, &hfd987193
ff c, d, a, b, x(k + 14), s13, &ha679438e
ff b, c, d, a, x(k + 15), s14, &h49b40821
gg a, b, c, d, x(k + 1), s21, &hf61e2562
gg d, a, b, c, x(k + 6), s22, &hc040b340
gg c, d, a, b, x(k + 11), s23, &h265e5a51
gg b, c, d, a, x(k + 0), s24, &he9b6c7aa
gg a, b, c, d, x(k + 5), s21, &hd62f105d
gg d, a, b, c, x(k + 10), s22, &h2441453
gg c, d, a, b, x(k + 15), s23, &hd8a1e681
gg b, c, d, a, x(k + 4), s24, &he7d3fbc8
gg a, b, c, d, x(k + 9), s21, &h21e1cde6
gg d, a, b, c, x(k + 14), s22, &hc33707d6
gg c, d, a, b, x(k + 3), s23, &hf4d50d87
gg b, c, d, a, x(k + 8), s24, &h455a14ed
gg a, b, c, d, x(k + 13), s21, &ha9e3e905
gg d, a, b, c, x(k + 2), s22, &hfcefa3f8
gg c, d, a, b, x(k + 7), s23, &h676f02d9
gg b, c, d, a, x(k + 12), s24, &h8d2a4c8a
hh a, b, c, d, x(k + 5), s31, &hfffa3942
hh d, a, b, c, x(k + 8), s32, &h8771f681
hh c, d, a, b, x(k + 11), s33, &h6d9d6122
hh b, c, d, a, x(k + 14), s34, &hfde5380c
hh a, b, c, d, x(k + 1), s31, &ha4beea44
hh d, a, b, c, x(k + 4), s32, &h4bdecfa9
hh c, d, a, b, x(k + 7), s33, &hf6bb4b60
hh b, c, d, a, x(k + 10), s34, &hbebfbc70
hh a, b, c, d, x(k + 13), s31, &h289b7ec6
hh d, a, b, c, x(k + 0), s32, &heaa127fa
hh c, d, a, b, x(k + 3), s33, &hd4ef3085
hh b, c, d, a, x(k + 6), s34, &h4881d05
hh a, b, c, d, x(k + 9), s31, &hd9d4d039
hh d, a, b, c, x(k + 12), s32, &he6db99e5
hh c, d, a, b, x(k + 15), s33, &h1fa27cf8
hh b, c, d, a, x(k + 2), s34, &hc4ac5665
ii a, b, c, d, x(k + 0), s41, &hf4292244
ii d, a, b, c, x(k + 7), s42, &h432aff97
ii c, d, a, b, x(k + 14), s43, &hab9423a7
ii b, c, d, a, x(k + 5), s44, &hfc93a039
ii a, b, c, d, x(k + 12), s41, &h655b59c3
ii d, a, b, c, x(k + 3), s42, &h8f0ccc92
ii c, d, a, b, x(k + 10), s43, &hffeff47d
ii b, c, d, a, x(k + 1), s44, &h85845dd1
ii a, b, c, d, x(k + 8), s41, &h6fa87e4f
ii d, a, b, c, x(k + 15), s42, &hfe2ce6e0
ii c, d, a, b, x(k + 6), s43, &ha3014314
ii b, c, d, a, x(k + 13), s44, &h4e0811a1
ii a, b, c, d, x(k + 4), s41, &hf7537e82
ii d, a, b, c, x(k + 11), s42, &hbd3af235
ii c, d, a, b, x(k + 2), s43, &h2ad7d2bb
ii b, c, d, a, x(k + 9), s44, &heb86d391
a = addunsigned(a, aa)
b = addunsigned(b, bb)
c = addunsigned(c, cc)
d = addunsigned(d, dd)
next
md5 = lcase(wordtohex(a) & wordtohex(b) & wordtohex(c) & wordtohex(d))
end function
5.sha256 加密,256位的加密哦!安全性更高!
private m_lonbits(30)
private m_l2power(30)
private k(63)
private const bits_to_a_byte = 8
private const bytes_to_a_word = 4
private const bits_to_a_word = 32
m_lonbits(0) = clng(1)
m_lonbits(1) = clng(3)
m_lonbits(2) = clng(7)
m_lonbits(3) = clng(15)
m_lonbits(4) = clng(31)
m_lonbits(5) = clng(63)
m_lonbits(6) = clng(127)
m_lonbits(7) = clng(255)
m_lonbits(8) = clng(511)
m_lonbits(9) = clng(1023)
m_lonbits(10) = clng(2047)
m_lonbits(11) = clng(4095)
m_lonbits(12) = clng(8191)
m_lonbits(13) = clng(16383)
m_lonbits(14) = clng(32767)
m_lonbits(15) = clng(65535)
m_lonbits(16) = clng(131071)
m_lonbits(17) = clng(262143)
m_lonbits(18) = clng(524287)
m_lonbits(19) = clng(1048575)
m_lonbits(20) = clng(2097151)
m_lonbits(21) = clng(4194303)
m_lonbits(22) = clng(8388607)
m_lonbits(23) = clng(16777215)
m_lonbits(24) = clng(33554431)
m_lonbits(25) = clng(67108863)
m_lonbits(26) = clng(134217727)
m_lonbits(27) = clng(268435455)
m_lonbits(28) = clng(536870911)
m_lonbits(29) = clng(1073741823)
m_lonbits(30) = clng(2147483647)
m_l2power(0) = clng(1)
m_l2power(1) = clng(2)
m_l2power(2) = clng(4)
m_l2power(3) = clng(8)
m_l2power(4) = clng(16)
m_l2power(5) = clng(32)
m_l2power(6) = clng(64)
m_l2power(7) = clng(128)
m_l2power(8) = clng(256)
m_l2power(9) = clng(512)
m_l2power(10) = clng(1024)
m_l2power(11) = clng(2048)
m_l2power(12) = clng(4096)
m_l2power(13) = clng(8192)
m_l2power(14) = clng(16384)
m_l2power(15) = clng(32768)
m_l2power(16) = clng(65536)
m_l2power(17) = clng(131072)
m_l2power(18) = clng(262144)
m_l2power(19) = clng(524288)
m_l2power(20) = clng(1048576)
m_l2power(21) = clng(2097152)
m_l2power(22) = clng(4194304)
m_l2power(23) = clng(8388608)
m_l2power(24) = clng(16777216)
m_l2power(25) = clng(33554432)
m_l2power(26) = clng(67108864)
m_l2power(27) = clng(134217728)
m_l2power(28) = clng(268435456)
m_l2power(29) = clng(536870912)
m_l2power(30) = clng(1073741824)
k(0) = &h428a2f98
k(1) = &h71374491
k(2) = &hb5c0fbcf
k(3) = &he9b5dba5
k(4) = &h3956c25b
k(5) = &h59f111f1
k(6) = &h923f82a4
k(7) = &hab1c5ed5
k(8) = &hd807aa98
k(9) = &h12835b01
k(10) = &h243185be
k(11) = &h550c7dc3
k(12) = &h72be5d74
k(13) = &h80deb1fe
k(14) = &h9bdc06a7
k(15) = &hc19bf174
k(16) = &he49b69c1
k(17) = &hefbe4786
k(18) = &hfc19dc6
k(19) = &h240ca1cc
k(20) = &h2de92c6f
k(21) = &h4a7484aa
k(22) = &h5cb0a9dc
k(23) = &h76f988da
k(24) = &h983e5152
k(25) = &ha831c66d
k(26) = &hb00327c8
k(27) = &hbf597fc7
k(28) = &hc6e00bf3
k(29) = &hd5a79147
k(30) = &h6ca6351
k(31) = &h14292967
k(32) = &h27b70a85
k(33) = &h2e1b2138
k(34) = &h4d2c6dfc
k(35) = &h53380d13
k(36) = &h650a7354
k(37) = &h766a0abb
k(38) = &h81c2c92e
k(39) = &h92722c85
k(40) = &ha2bfe8a1
k(41) = &ha81a664b
k(42) = &hc24b8b70
k(43) = &hc76c51a3
k(44) = &hd192e819
k(45) = &hd6990624
k(46) = &hf40e3585
k(47) = &h106aa070
k(48) = &h19a4c116
k(49) = &h1e376c08
k(50) = &h2748774c
k(51) = &h34b0bcb5
k(52) = &h391c0cb3
k(53) = &h4ed8aa4a
k(54) = &h5b9cca4f
k(55) = &h682e6ff3
k(56) = &h748f82ee
k(57) = &h78a5636f
k(58) = &h84c87814
k(59) = &h8cc70208
k(60) = &h90befffa
k(61) = &ha4506ceb
k(62) = &hbef9a3f7
k(63) = &hc67178f2
private function lshift(lvalue, ishiftbits)
if ishiftbits = 0 then
lshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and 1 then
lshift = &h80000000
else
lshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
if (lvalue and m_l2power(31 - ishiftbits)) then
lshift = ((lvalue and m_lonbits(31 - (ishiftbits + 1))) * m_l2power(ishiftbits)) or &h80000000
else
lshift = ((lvalue and m_lonbits(31 - ishiftbits)) * m_l2power(ishiftbits))
end if
end function
private function rshift(lvalue, ishiftbits)
if ishiftbits = 0 then
rshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and &h80000000 then
rshift = 1
else
rshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
rshift = (lvalue and &h7ffffffe) m_l2power(ishiftbits)
if (lvalue and &h80000000) then
rshift = (rshift or (&h40000000 m_l2power(ishiftbits - 1)))
end if
end function
private function addunsigned(lx, ly)
dim lx4
dim ly4
dim lx8
dim ly8
dim lresult
lx8 = lx and &h80000000
ly8 = ly and &h80000000
lx4 = lx and &h40000000
ly4 = ly and &h40000000
lresult = (lx and &h3fffffff) + (ly and &h3fffffff)
if lx4 and ly4 then
lresult = lresult xor &h80000000 xor lx8 xor ly8
elseif lx4 or ly4 then
if lresult and &h40000000 then
lresult = lresult xor &hc0000000 xor lx8 xor ly8
else
lresult = lresult xor &h40000000 xor lx8 xor ly8
end if
else
lresult = lresult xor lx8 xor ly8
end if
addunsigned = lresult
end function
private function ch(x, y, z)
ch = ((x and y) xor ((not x) and z))
end function
private function maj(x, y, z)
maj = ((x and y) xor (x and z) xor (y and z))
end function
private function s(x, n)
s = (rshift(x, (n and m_lonbits(4))) or lshift(x, (32 - (n and m_lonbits(4)))))
end function
private function r(x, n)
r = rshift(x, cint(n and m_lonbits(4)))
end function
private function sigma0(x)
sigma0 = (s(x, 2) xor s(x, 13) xor s(x, 22))
end function
private function sigma1(x)
sigma1 = (s(x, 6) xor s(x, 11) xor s(x, 25))
end function
private function gamma0(x)
gamma0 = (s(x, 7) xor s(x, 18) xor r(x, 3))
end function
private function gamma1(x)
gamma1 = (s(x, 17) xor s(x, 19) xor r(x, 10))
end function
private function converttowordarray(smessage)
dim lmessagelength
dim lnumberofwords
dim lwordarray()
dim lbyteposition
dim lbytecount
dim lwordcount
dim lbyte
const modulus_bits = 512
const congruent_bits = 448
lmessagelength = len(smessage)
lnumberofwords = (((lmessagelength + ((modulus_bits - congruent_bits) bits_to_a_byte)) (modulus_bits bits_to_a_byte)) + 1) * (modulus_bits bits_to_a_word)
redim lwordarray(lnumberofwords - 1)
lbyteposition = 0
lbytecount = 0
do until lbytecount >= lmessagelength
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (3 - (lbytecount mod bytes_to_a_word)) * bits_to_a_byte
lbyte = ascb(mid(smessage, lbytecount + 1, 1))
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(lbyte, lbyteposition)
lbytecount = lbytecount + 1
loop
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (3 - (lbytecount mod bytes_to_a_word)) * bits_to_a_byte
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(&h80, lbyteposition)
lwordarray(lnumberofwords - 1) = lshift(lmessagelength, 3)
lwordarray(lnumberofwords - 2) = rshift(lmessagelength, 29)
converttowordarray = lwordarray
end function
public function sha256(smessage)
dim hash(7)
dim m
dim w(63)
dim a
dim b
dim c
dim d
dim e
dim f
dim g
dim h
dim i
dim j
dim t1
dim t2
hash(0) = &h6a09e667
hash(1) = &hbb67ae85
hash(2) = &h3c6ef372
hash(3) = &ha54ff53a
hash(4) = &h510e527f
hash(5) = &h9b05688c
hash(6) = &h1f83d9ab
hash(7) = &h5be0cd19
m = converttowordarray(smessage)
for i = 0 to ubound(m) step 16
a = hash(0)
b = hash(1)
c = hash(2)
d = hash(3)
e = hash(4)
f = hash(5)
g = hash(6)
h = hash(7)
for j = 0 to 63
if j < 16 then
w(j) = m(j + i)
else
w(j) = addunsigned(addunsigned(addunsigned(gamma1(w(j - 2)), w(j - 7)), gamma0(w(j - 15))), w(j - 16))
end if
t1 = addunsigned(addunsigned(addunsigned(addunsigned(h, sigma1(e)), ch(e, f, g)), k(j)), w(j))
t2 = addunsigned(sigma0(a), maj(a, b, c))
h = g
g = f
f = e
e = addunsigned(d, t1)
d = c
c = b
b = a
a = addunsigned(t1, t2)
next
hash(0) = addunsigned(a, hash(0))
hash(1) = addunsigned(b, hash(1))
hash(2) = addunsigned(c, hash(2))
hash(3) = addunsigned(d, hash(3))
hash(4) = addunsigned(e, hash(4))
hash(5) = addunsigned(f, hash(5))
hash(6) = addunsigned(g, hash(6))
hash(7) = addunsigned(h, hash(7))
next
sha256 = lcase(right("00000000" & hex(hash(0)), 8) & right("00000000" & hex(hash(1)), 8) & right("00000000" & hex(hash(2)), 8) & right("00000000" & hex(hash(3)), 8) & right("00000000" & hex(hash(4)), 8) & right("00000000" & hex(hash(5)), 8) & right("00000000" & hex(hash(6)), 8) & right("00000000" & hex(hash(7)), 8))
end function
6.一个if语句的加工,以后可以用类似于php或js的 if () ? ..
...代码了
function iif(condition, valueiftrue, valueiffalse)
if condition then
iif = valueiftrue
else
iif = valueiffalse
end if
end function
7.ase加密函数
private m_lonbits(30)
private m_l2power(30)
private m_bytonbits(7)
private m_byt2power(7)
private m_inco(3)
private m_fbsub(255)
private m_rbsub(255)
private m_ptab(255)
private m_ltab(255)
private m_ftable(255)
private m_rtable(255)
private m_rco(29)
private m_nk
private m_nb
private m_nr
private m_fi(23)
private m_ri(23)
private m_fkey(119)
private m_rkey(119)
m_inco(0) = &hb
m_inco(1) = &hd
m_inco(2) = &h9
m_inco(3) = &he
m_bytonbits(0) = 1
m_bytonbits(1) = 3
m_bytonbits(2) = 7
m_bytonbits(3) = 15
m_bytonbits(4) = 31
m_bytonbits(5) = 63
m_bytonbits(6) = 127
m_bytonbits(7) = 255
m_byt2power(0) = 1
m_byt2power(1) = 2
m_byt2power(2) = 4
m_byt2power(3) = 8
m_byt2power(4) = 16
m_byt2power(5) = 32
m_byt2power(6) = 64
m_byt2power(7) = 128
m_lonbits(0) = 1
m_lonbits(1) = 3
m_lonbits(2) = 7
m_lonbits(3) = 15
m_lonbits(4) = 31
m_lonbits(5) = 63
m_lonbits(6) = 127
m_lonbits(7) = 255
m_lonbits(8) = 511
m_lonbits(9) = 1023
m_lonbits(10) = 2047
m_lonbits(11) = 4095
m_lonbits(12) = 8191
m_lonbits(13) = 16383
m_lonbits(14) = 32767
m_lonbits(15) = 65535
m_lonbits(16) = 131071
m_lonbits(17) = 262143
m_lonbits(18) = 524287
m_lonbits(19) = 1048575
m_lonbits(20) = 2097151
m_lonbits(21) = 4194303
m_lonbits(22) = 8388607
m_lonbits(23) = 16777215
m_lonbits(24) = 33554431
m_lonbits(25) = 67108863
m_lonbits(26) = 134217727
m_lonbits(27) = 268435455
m_lonbits(28) = 536870911
m_lonbits(29) = 1073741823
m_lonbits(30) = 2147483647
m_l2power(0) = 1
m_l2power(1) = 2
m_l2power(2) = 4
m_l2power(3) = 8
m_l2power(4) = 16
m_l2power(5) = 32
m_l2power(6) = 64
m_l2power(7) = 128
m_l2power(8) = 256
m_l2power(9) = 512
m_l2power(10) = 1024
m_l2power(11) = 2048
m_l2power(12) = 4096
m_l2power(13) = 8192
m_l2power(14) = 16384
m_l2power(15) = 32768
m_l2power(16) = 65536
m_l2power(17) = 131072
m_l2power(18) = 262144
m_l2power(19) = 524288
m_l2power(20) = 1048576
m_l2power(21) = 2097152
m_l2power(22) = 4194304
m_l2power(23) = 8388608
m_l2power(24) = 16777216
m_l2power(25) = 33554432
m_l2power(26) = 67108864
m_l2power(27) = 134217728
m_l2power(28) = 268435456
m_l2power(29) = 536870912
m_l2power(30) = 1073741824
private function lshift(lvalue, ishiftbits)
if ishiftbits = 0 then
lshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and 1 then
lshift = &h80000000
else
lshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
if (lvalue and m_l2power(31 - ishiftbits)) then
lshift = ((lvalue and m_lonbits(31 - (ishiftbits + 1))) * m_l2power(ishiftbits)) or &h80000000
else
lshift = ((lvalue and m_lonbits(31 - ishiftbits)) * m_l2power(ishiftbits))
end if
end function
private function rshift(lvalue, ishiftbits)
if ishiftbits = 0 then
rshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and &h80000000 then
rshift = 1
else
rshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
rshift = (lvalue and &h7ffffffe) m_l2power(ishiftbits)
if (lvalue and &h80000000) then
rshift = (rshift or (&h40000000 m_l2power(ishiftbits - 1)))
end if
end function
private function lshiftbyte(bytvalue, bytshiftbits)
if bytshiftbits = 0 then
lshiftbyte = bytvalue
exit function
elseif bytshiftbits = 7 then
if bytvalue and 1 then
lshiftbyte = &h80
else
lshiftbyte = 0
end if
exit function
elseif bytshiftbits < 0 or bytshiftbits > 7 then
err.raise 6
end if
lshiftbyte = ((bytvalue and m_bytonbits(7 - bytshiftbits)) * m_byt2power(bytshiftbits))
end function
private function rshiftbyte(bytvalue, bytshiftbits)
if bytshiftbits = 0 then
rshiftbyte = bytvalue
exit function
elseif bytshiftbits = 7 then
if bytvalue and &h80 then
rshiftbyte = 1
else
rshiftbyte = 0
end if
exit function
elseif bytshiftbits < 0 or bytshiftbits > 7 then
err.raise 6
end if
rshiftbyte = bytvalue m_byt2power(bytshiftbits)
end function
private function rotateleft(lvalue, ishiftbits)
rotateleft = lshift(lvalue, ishiftbits) or rshift(lvalue, (32 - ishiftbits))
end function
private function rotateleftbyte(bytvalue, bytshiftbits)
rotateleftbyte = lshiftbyte(bytvalue, bytshiftbits) or rshiftbyte(bytvalue, (8 - bytshiftbits))
end function
private function pack(b())
dim lcount
dim ltemp
for lcount = 0 to 3
ltemp = b(lcount)
pack = pack or lshift(ltemp, (lcount * 8))
next
end function
private function packfrom(b(), k)
dim lcount
dim ltemp
for lcount = 0 to 3
ltemp = b(lcount + k)
packfrom = packfrom or lshift(ltemp, (lcount * 8))
next
end function
private sub unpack(a, b())
b(0) = a and m_lonbits(7)
b(1) = rshift(a, 8) and m_lonbits(7)
b(2) = rshift(a, 16) and m_lonbits(7)
b(3) = rshift(a, 24) and m_lonbits(7)
end sub
private sub unpackfrom(a, b(), k)
b(0 + k) = a and m_lonbits(7)
b(1 + k) = rshift(a, 8) and m_lonbits(7)
b(2 + k) = rshift(a, 16) and m_lonbits(7)
b(3 + k) = rshift(a, 24) and m_lonbits(7)
end sub
private function xtime(a)
dim b
if (a and &h80) then
b = &h1b
else
b = 0
end if
xtime = lshiftbyte(a, 1)
xtime = xtime xor b
end function
private function bmul(x, y)
if x <> 0 and y <> 0 then
bmul = m_ptab((clng(m_ltab(x)) + clng(m_ltab(y))) mod 255)
else
bmul = 0
end if
end function
private function subbyte(a)
dim b(3)
unpack a, b
b(0) = m_fbsub(b(0))
b(1) = m_fbsub(b(1))
b(2) = m_fbsub(b(2))
b(3) = m_fbsub(b(3))
subbyte = pack(b)
end function
private function product(x, y)
dim xb(3)
dim yb(3)
unpack x, xb
unpack y, yb
product = bmul(xb(0), yb(0)) xor bmul(xb(1), yb(1)) xor bmul(xb(2), yb(2)) xor bmul(xb(3), yb(3))
end function
private function invmixcol(x)
dim y
dim m
dim b(3)
m = pack(m_inco)
b(3) = product(m, x)
m = rotateleft(m, 24)
b(2) = product(m, x)
m = rotateleft(m, 24)
b(1) = product(m, x)
m = rotateleft(m, 24)
b(0) = product(m, x)
y = pack(b)
invmixcol = y
end function
private function bytesub(x)
dim y
dim z
z = x
y = m_ptab(255 - m_ltab(z))
z = y
z = rotateleftbyte(z, 1)
y = y xor z
z = rotateleftbyte(z, 1)
y = y xor z
z = rotateleftbyte(z, 1)
y = y xor z
z = rotateleftbyte(z, 1)
y = y xor z
y = y xor &h63
bytesub = y
end function
public sub gentables()
dim i
dim y
dim b(3)
dim ib
m_ltab(0) = 0
m_ptab(0) = 1
m_ltab(1) = 0
m_ptab(1) = 3
m_ltab(3) = 1
for i = 2 to 255
m_ptab(i) = m_ptab(i - 1) xor xtime(m_ptab(i - 1))
m_ltab(m_ptab(i)) = i
next
m_fbsub(0) = &h63
m_rbsub(&h63) = 0
for i = 1 to 255
ib = i
y = bytesub(ib)
m_fbsub(i) = y
m_rbsub(y) = i
next
y = 1
for i = 0 to 29
m_rco(i) = y
y = xtime(y)
next
for i = 0 to 255
y = m_fbsub(i)
b(3) = y xor xtime(y)
b(2) = y
b(1) = y
b(0) = xtime(y)
m_ftable(i) = pack(b)
y = m_rbsub(i)
b(3) = bmul(m_inco(0), y)
b(2) = bmul(m_inco(1), y)
b(1) = bmul(m_inco(2), y)
b(0) = bmul(m_inco(3), y)
m_rtable(i) = pack(b)
next
end sub
public sub gkey(nb, nk, key())
dim i
dim j
dim k
dim m
dim n
dim c1
dim c2
dim c3
dim cipherkey(7)
m_nb = nb
m_nk = nk
if m_nb >= m_nk then
m_nr = 6 + m_nb
else
m_nr = 6 + m_nk
end if
c1 = 1
if m_nb < 8 then
c2 = 2
c3 = 3
else
c2 = 3
c3 = 4
end if
for j = 0 to nb - 1
m = j * 3
m_fi(m) = (j + c1) mod nb
m_fi(m + 1) = (j + c2) mod nb
m_fi(m + 2) = (j + c3) mod nb
m_ri(m) = (nb + j - c1) mod nb
m_ri(m + 1) = (nb + j - c2) mod nb
m_ri(m + 2) = (nb + j - c3) mod nb
next
n = m_nb * (m_nr + 1)
for i = 0 to m_nk - 1
j = i * 4
cipherkey(i) = packfrom(key, j)
next
for i = 0 to m_nk - 1
m_fkey(i) = cipherkey(i)
next
j = m_nk
k = 0
do while j < n
m_fkey(j) = m_fkey(j - m_nk) xor _
subbyte(rotateleft(m_fkey(j - 1), 24)) xor m_rco(k)
if m_nk <= 6 then
i = 1
do while i < m_nk and (i + j) < n
m_fkey(i + j) = m_fkey(i + j - m_nk) xor _
m_fkey(i + j - 1)
i = i + 1
loop
else
i = 1
do while i < 4 and (i + j) < n
m_fkey(i + j) = m_fkey(i + j - m_nk) xor _
m_fkey(i + j - 1)
i = i + 1
loop
if j + 4 < n then
m_fkey(j + 4) = m_fkey(j + 4 - m_nk) xor _
subbyte(m_fkey(j + 3))
end if
i = 5
do while i < m_nk and (i + j) < n
m_fkey(i + j) = m_fkey(i + j - m_nk) xor _
m_fkey(i + j - 1)
i = i + 1
loop
end if
j = j + m_nk
k = k + 1
loop
for j = 0 to m_nb - 1
m_rkey(j + n - nb) = m_fkey(j)
next
i = m_nb
do while i < n - m_nb
k = n - m_nb - i
for j = 0 to m_nb - 1
m_rkey(k + j) = invmixcol(m_fkey(i + j))
next
i = i + m_nb
loop
j = n - m_nb
do while j < n
m_rkey(j - n + m_nb) = m_fkey(j)
j = j + 1
loop
end sub
public sub encrypt(buff())
dim i
dim j
dim k
dim m
dim a(7)
dim b(7)
dim x
dim y
dim t
for i = 0 to m_nb - 1
j = i * 4
a(i) = packfrom(buff, j)
a(i) = a(i) xor m_fkey(i)
next
k = m_nb
x = a
y = b
for i = 1 to m_nr - 1
for j = 0 to m_nb - 1
m = j * 3
y(j) = m_fkey(k) xor m_ftable(x(j) and m_lonbits(7)) xor _
rotateleft(m_ftable(rshift(x(m_fi(m)), 8) and m_lonbits(7)), 8) xor _
rotateleft(m_ftable(rshift(x(m_fi(m + 1)), 16) and m_lonbits(7)), 16) xor _
rotateleft(m_ftable(rshift(x(m_fi(m + 2)), 24) and m_lonbits(7)), 24)
k = k + 1
next
t = x
x = y
y = t
next
for j = 0 to m_nb - 1
m = j * 3
y(j) = m_fkey(k) xor m_fbsub(x(j) and m_lonbits(7)) xor _
rotateleft(m_fbsub(rshift(x(m_fi(m)), 8) and m_lonbits(7)), 8) xor _
rotateleft(m_fbsub(rshift(x(m_fi(m + 1)), 16) and m_lonbits(7)), 16) xor _
rotateleft(m_fbsub(rshift(x(m_fi(m + 2)), 24) and m_lonbits(7)), 24)
k = k + 1
next
for i = 0 to m_nb - 1
j = i * 4
unpackfrom y(i), buff, j
x(i) = 0
y(i) = 0
next
end sub
public sub decrypt(buff())
dim i
dim j
dim k
dim m
dim a(7)
dim b(7)
dim x
dim y
dim t
for i = 0 to m_nb - 1
j = i * 4
a(i) = packfrom(buff, j)
a(i) = a(i) xor m_rkey(i)
next
k = m_nb
x = a
y = b
for i = 1 to m_nr - 1
for j = 0 to m_nb - 1
m = j * 3
y(j) = m_rkey(k) xor m_rtable(x(j) and m_lonbits(7)) xor _
rotateleft(m_rtable(rshift(x(m_ri(m)), 8) and m_lonbits(7)), 8) xor _
rotateleft(m_rtable(rshift(x(m_ri(m + 1)), 16) and m_lonbits(7)), 16) xor _
rotateleft(m_rtable(rshift(x(m_ri(m + 2)), 24) and m_lonbits(7)), 24)
k = k + 1
next
t = x
x = y
y = t
next
for j = 0 to m_nb - 1
m = j * 3
y(j) = m_rkey(k) xor m_rbsub(x(j) and m_lonbits(7)) xor _
rotateleft(m_rbsub(rshift(x(m_ri(m)), 8) and m_lonbits(7)), 8) xor _
rotateleft(m_rbsub(rshift(x(m_ri(m + 1)), 16) and m_lonbits(7)), 16) xor _
rotateleft(m_rbsub(rshift(x(m_ri(m + 2)), 24) and m_lonbits(7)), 24)
k = k + 1
next
for i = 0 to m_nb - 1
j = i * 4
unpackfrom y(i), buff, j
x(i) = 0
y(i) = 0
next
end sub
private function isinitialized(varray)
on error resume next
isinitialized = isnumeric(ubound(varray))
end function
private sub copybytesasp(bytdest, ldeststart, bytsource(), lsourcestart, llength)
dim lcount
lcount = 0
do
bytdest(ldeststart + lcount) = bytsource(lsourcestart + lcount)
lcount = lcount + 1
loop until lcount = llength
end sub
public function encryptdata(bytmessage, bytpassword)
dim bytkey(31)
dim bytin()
dim bytout()
dim byttemp(31)
dim lcount
dim llength
dim lencodedlength
dim bytlen(3)
dim lposition
if not isinitialized(bytmessage) then
exit function
end if
if not isinitialized(bytpassword) then
exit function
end if
for lcount = 0 to ubound(bytpassword)
bytkey(lcount) = bytpassword(lcount)
if lcount = 31 then
exit for
end if
next
gentables
gkey 8, 8, bytkey
llength = ubound(bytmessage) + 1
lencodedlength = llength + 4
if lencodedlength mod 32 <> 0 then
lencodedlength = lencodedlength + 32 - (lencodedlength mod 32)
end if
redim bytin(lencodedlength - 1)
redim bytout(lencodedlength - 1)
unpack llength, bytin
copybytesasp bytin, 4, bytmessage, 0, llength
for lcount = 0 to lencodedlength - 1 step 32
copybytesasp byttemp, 0, bytin, lcount, 32
encrypt byttemp
copybytesasp bytout, lcount, byttemp, 0, 32
next
encryptdata = bytout
end function
public function decryptdata(bytin, bytpassword)
dim bytmessage()
dim bytkey(31)
dim bytout()
dim byttemp(31)
dim lcount
dim llength
dim lencodedlength
dim bytlen(3)
dim lposition
if not isinitialized(bytin) then
exit function
end if
if not isinitialized(bytpassword) then
exit function
end if
lencodedlength = ubound(bytin) + 1
if lencodedlength mod 32 <> 0 then
exit function
end if
for lcount = 0 to ubound(bytpassword)
bytkey(lcount) = bytpassword(lcount)
if lcount = 31 then
exit for
end if
next
gentables
gkey 8, 8, bytkey
redim bytout(lencodedlength - 1)
for lcount = 0 to lencodedlength - 1 step 32
copybytesasp byttemp, 0, bytin, lcount, 32
decrypt byttemp
copybytesasp bytout, lcount, byttemp, 0, 32
next
llength = pack(bytout)
if llength > lencodedlength - 4 then
exit function
end if
redim bytmessage(llength - 1)
copybytesasp bytmessage, 0, bytout, 4, llength
decryptdata = bytmessage
end function
8.一个日期转换函数
function formatdate(byval strdate, byval strformat)
' accepts strdate as a valid date/time,
' strformat as the output template.
' the function finds each item in the
' template and replaces it with the
' relevant information extracted from strdate.
' you are free to use this code provided the following line remains
' www.adopenstatic.com/resources/code/formatdate.asp
' template items
' %m month as a decimal no. 2
' %m month as a padded decimal no. 02
' %b full month name february
' %b abbreviated month name feb
' %d day of the month eg 23
' %d padded day of the month eg 09
' %o ordinal of day of month (eg st or rd or nd)
' %j day of the year 54
' %y year with century 1998
' %y year without century 98
' %w weekday as integer (0 is sunday)
' %a abbreviated day name fri
' %a weekday name friday
' %h hour in 24 hour format 24
' %h hour in 12 hour format 12
' %n minute as an integer 01
' %n minute as optional if minute <> 00
' %s second as an integer 55
' %p am/pm indicator pm
on error resume next
dim intpositem
dim int12hourpart
dim str24hourpart
dim strminutepart
dim strsecondpart
dim strampm
' insert month numbers
strformat = replace(strformat, "%m", datepart("m", strdate), 1, -1, vbbinarycompare)
' insert padded month numbers
strformat = replace(strformat, "%m", right("0" & datepart("m", strdate), 2), 1, -1, vbbinarycompare)
' insert non-abbreviated month names
strformat = replace(strformat, "%b", monthname(datepart("m", strdate), false), 1, -1, vbbinarycompare)
' insert abbreviated month names
strformat = replace(strformat, "%b", monthname(datepart("m", strdate), true), 1, -1, vbbinarycompare)
' insert day of month
strformat = replace(strformat, "%d", datepart("d", strdate), 1, -1, vbbinarycompare)
' insert padded day of month
strformat = replace(strformat, "%d", right ("0" & datepart("d", strdate), 2), 1, -1, vbbinarycompare)
' insert day of month ordinal (eg st, th, or rd)
strformat = replace(strformat, "%o", getdayordinal(day(strdate)), 1, -1, vbbinarycompare)
' insert day of year
strformat = replace(strformat, "%j", datepart("y", strdate), 1, -1, vbbinarycompare)
' insert long year (4 digit)
strformat = replace(strformat, "%y", datepart("yyyy", strdate), 1, -1, vbbinarycompare)
' insert short year (2 digit)
strformat = replace(strformat, "%y", right(datepart("yyyy", strdate), 2), 1, -1, vbbinarycompare)
' insert weekday as integer (eg 0 = sunday)
strformat = replace(strformat, "%w", datepart("w", strdate, 1), 1, -1, vbbinarycompare)
' insert abbreviated weekday name (eg sun)
strformat = replace(strformat, "%a", weekdayname(datepart("w", strdate, 1), true), 1, -1, vbbinarycompare)
' insert non-abbreviated weekday name
strformat = replace(strformat, "%a", weekdayname(datepart("w", strdate, 1), false), 1, -1, vbbinarycompare)
' insert hour in 24hr format
str24hourpart = datepart("h", strdate)
if len(str24hourpart) < 2 then str24hourpart = "0" & str24hourpart
strformat = replace(strformat, "%h", str24hourpart, 1, -1, vbbinarycompare)
' insert hour in 12hr format
int12hourpart = datepart("h", strdate) mod 12
if int12hourpart = 0 then int12hourpart = 12
strformat = replace(strformat, "%h", int12hourpart, 1, -1, vbbinarycompare)
' insert minutes
strminutepart = datepart("n", strdate)
if len(strminutepart) < 2 then strminutepart = "0" & strminutepart
strformat = replace(strformat, "%n", strminutepart, 1, -1, vbbinarycompare)
' insert optional minutes
if cint(strminutepart) = 0 then
strformat = replace(strformat, "%n", "", 1, -1, vbbinarycompare)
else
if cint(strminutepart) < 10 then strminutepart = "0" & strminutepart
strminutepart = ":" & strminutepart
strformat = replace(strformat, "%n", strminutepart, 1, -1, vbbinarycompare)
end if
' insert seconds
strsecondpart = datepart("s", strdate)
if len(strsecondpart) < 2 then strsecondpart = "0" & strsecondpart
strformat = replace(strformat, "%s", strsecondpart, 1, -1, vbbinarycompare)
' insert am/pm indicator
if datepart("h", strdate) >= 12 then
strampm = "pm"
else
strampm = "am"
end if
strformat = replace(strformat, "%p", strampm, 1, -1, vbbinarycompare)
formatdate = strformat
end function
function getdayordinal( _
byval intday _
)
' accepts a day of the month
' as an integer and returns the
' appropriate suffix
on error resume next
dim strord
select case intday
case 1, 21, 31
strord = "st"
case 2, 22
strord = "nd"
case 3, 23
strord = "rd"
case else
strord = "th"
end select
getdayordinal = strord
end function
%>
<%
dim db
db = "dbms.mdb"
'******************************************************************
'执行sql语句,不返回值,sql语句最好是如下:
'update 表名 set 字段名=value,字段名=value where 字段名=value
'delete from 表名 where 字段名=value
'insert into 表名 (字段名,字段名) values (value,value)
'******************************************************************
sub noresult(sql)
dim conn
dim connstr
set conn = server.createobject("adodb.connection")
connstr = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(""&db&"")
conn.open connstr
conn.execute sql
conn.close
set conn = nothing
end sub
'*******************************************************************
'执行select语句,返回recordset对象。该对象只读。也就是不能更新
'*******************************************************************
function result(sql)
dim conn
dim connstr
dim rcs
set conn = server.createobject("adodb.connection")
connstr = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(""&db&"")
conn.open connstr
set rcs = server.createobject("adodb.recordset")
rcs.open sql, conn, 1, 1
set result = rcs
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
'*******************************************************************
' 把html标记替换
'*******************************************************************
function htmlencode2(str)
dim result
dim l
if isnull(str) then
htmlencode2 = ""
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)
result = result + "<br>"
case chr(34)
result = result + """%>
<%
cleft(string, length) 返回指定数目的从字符串的左边算起的字符,区分单双字节。
如:
dim mystring, leftstring
mystring = "文字测试vbscript"
leftstring = cleft(mystring, 10)
返回 "文字测试vb"。
myrandc(n) 生成随机字符,n为字符的个数
如:
response.write myrandn(10)
输出10个随机字符
myrandn(n) 生成随机数字,n为数字的个数
如:
response.write myrandn(10)
输出10个随机数字
formatquerystr(str) 格式化sql中的like字符串.
如:
q = request("q")
q = formatquerystr(q)
sql = "select * from [table] where aa like '%"& q &"%'"
getrnd(min, max) 返回min - max之间的一个随机数
如:
response.write getrnd(100, 200)
输出大于100到200之间的一个随机数
function cleft(str, n)
dim str1, str2, alln, islefted
str2 = ""
alln = 0
str1 = str
islefted = false
if isnull(str) then
cleft = ""
exit function
end if
for i = 1 to len(str1)
nowstr = mid(str1, i, 1)
if asc(nowstr)<0 then
alln = alln + 2
else
alln = alln + 1
end if
if (alln<= n) then
str2 = str2 & nowstr
else
islefted = true
exit for
end if
next
if islefted then
str2 = str2 & ".."
end if
cleft = str2
end function
function myrandc(n) '生成随机字符,n为字符的个数
dim thechr
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
function myrandn(n) '生成随机数字,n为数字的个数
dim thechr
thechr = ""
for i = 1 to n
dim znum, znum2
randomize
znum = cint(9 * rnd)
znum = znum + 48
thechr = thechr & chr(znum)
next
myrandn = thechr
end function
function formatquerystr(str) '格式化sql中的like字符串
dim nstr
nstr = str
nstr = replace(nstr, chr(0), "")
nstr = replace(nstr, "'", "''")
nstr = replace(nstr, "[", "[[]")
nstr = replace(nstr, "%", "[%]")
formatquerystr = nstr
end function
function getrnd(min, max)
randomize
getrnd = int((max - min + 1) * rnd + min)
end function
'*******************************************************************
'取得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
'*******************************************************************
'转换ip地址
'*******************************************************************
function cip(sip)
tip = cstr(sip)
sip1 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip2 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip3 = left(tip, cint(instr(tip, ".") -1))
sip4 = mid(tip, cint(instr(tip, ".") + 1))
cip = cint(sip1) * 256 * 256 * 256 + cint(sip2) * 256 * 256 + cint(sip3) * 256 + cint(sip4)
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, ">", ">")
fstring = replace(fstring, "<", "<")
fstring = replace(fstring, chr(32), " ")
fstring = replace(fstring, chr(9), " ")
fstring = replace(fstring, chr(34), """)
fstring = replace(fstring, chr(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
%>
<%
cleft(string, length) 返回指定数目的从字符串的左边算起的字符,区分单双字节。
如:
dim mystring, leftstring
mystring = "文字测试vbscript"
leftstring = cleft(mystring, 10)
返回 "文字测试vb"。
myrandc(n) 生成随机字符,n为字符的个数
如:
response.write myrandn(10)
输出10个随机字符
myrandn(n) 生成随机数字,n为数字的个数
如:
response.write myrandn(10)
输出10个随机数字
formatquerystr(str) 格式化sql中的like字符串.
如:
q = request("q")
q = formatquerystr(q)
sql = "select * from [table] where aa like '%"& q &"%'"
getrnd(min, max) 返回min - max之间的一个随机数
如:
response.write getrnd(100, 200)
输出大于100到200之间的一个随机数
function cleft(str, n)
dim str1, str2, alln, islefted
str2 = ""
alln = 0
str1 = str
islefted = false
if isnull(str) then
cleft = ""
exit function
end if
for i = 1 to len(str1)
nowstr = mid(str1, i, 1)
if asc(nowstr)<0 then
alln = alln + 2
else
alln = alln + 1
end if
if (alln<= n) then
str2 = str2 & nowstr
else
islefted = true
exit for
end if
next
if islefted then
str2 = str2 & ".."
end if
cleft = str2
end function
function myrandc(n) '生成随机字符,n为字符的个数
dim thechr
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
function myrandn(n) '生成随机数字,n为数字的个数
dim thechr
thechr = ""
for i = 1 to n
dim znum, znum2
randomize
znum = cint(9 * rnd)
znum = znum + 48
thechr = thechr & chr(znum)
next
myrandn = thechr
end function
function formatquerystr(str) '格式化sql中的like字符串
dim nstr
nstr = str
nstr = replace(nstr, chr(0), "")
nstr = replace(nstr, "'", "''")
nstr = replace(nstr, "[", "[[]")
nstr = replace(nstr, "%", "[%]")
formatquerystr = nstr
end function
function getrnd(min, max)
randomize
getrnd = int((max - min + 1) * rnd + min)
end function
'*******************************************************************
'取得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
'*******************************************************************
'转换ip地址
'*******************************************************************
function cip(sip)
tip = cstr(sip)
sip1 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip2 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip3 = left(tip, cint(instr(tip, ".") -1))
sip4 = mid(tip, cint(instr(tip, ".") + 1))
cip = cint(sip1) * 256 * 256 * 256 + cint(sip2) * 256 * 256 + cint(sip3) * 256 + cint(sip4)
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, ">", ">")
fstring = replace(fstring, "<", "<")
fstring = replace(fstring, chr(32), " ")
fstring = replace(fstring, chr(9), " ")
fstring = replace(fstring, chr(34), """)
fstring = replace(fstring, chr(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
%>
11.access数据库连接:
<%
option explicit
dim startime, endtime, conn, connstr, db
startime = timer()
'更改数据库名字
db = "data/dvbbs5.mdb"
set conn = server.createobject("adodb.connection")
connstr = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(db)
'如果你的服务器采用较老版本access驱动,请用下面连接方法
'connstr="driver={microsoft access driver (*.mdb)};dbq=" & server.mappath(db)
conn.open connstr
function closedatabase
conn.close
set conn = nothing
end function
%>
12.sql数据库连接:
<%
option explicit
dim startime, endtime, conn, connstr, db
startime = timer()
connstr = "driver={sql server};server=hudenq-n11t33nb;uid=sa;pwd=xsfeihu;database=dvbbs"
set conn = server.createobject("adodb.connection")
conn.open connstr
function closedatabase
conn.close
set conn = nothing
end function
%>
13.用键盘打开网页代码:
<script language="javascript">
function ctlent(eventobject)
{
if((event.ctrlkey && window.event.keycode==13)||(event.altkey && window.event.keycode==83))
{
window.open('网址','','')
}
}
</script>
这里是ctrl+enter和alt+s的代码 自己查下键盘的ascii码再换就行
14.让层不被控件复盖代码:
<div z-index:2><object ***></object></div> # 前面
<div z-index:1><object ***></object></div> # 后面
<div id="layer2" style="position:absolute; top:40;width:400px; height:95px;z-index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%></td></tr></table><iframe width=0 height=0></iframe></div>
<div id="layer1" style="position:absolute; top:50;width:200px; height:115px;z-index:1"><iframe height=100% width=100%></iframe></div>
15.动网flash广告代码:
<object classid="clsid27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="468" height="60"><param name=movie value="images/yj16d.swf"><param name=quality value=high><embed src="images/dvbanner.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash";;; type="application/x-shockwave-flash" width="468" height="60"></embed></object>
16.vbs弹出窗口小代码:
<script language=vbscript>
msgbox"你还没有注册或登陆论坛","0","精品论坛"
location.href = "login.asp"
</script>
16.使用fso修改文件特定内容的函数
<%
function fsochange(filename, target, string)
dim objfso, objcountfile, filetempdata
set objfso = server.createobject("scripting.filesystemobject")
set objcountfile = objfso.opentextfile(server.mappath(filename), 1, true)
filetempdata = objcountfile.readall
objcountfile.close
filetempdata = replace(filetempdata, target, string)
set objcountfile = objfso.createtextfile(server.mappath(filename), true)
objcountfile.write filetempdata
objcountfile.close
set objcountfile = nothing
set objfso = nothing
end function
%>
17.使用fso读取文件内容的函数
<%
function fsofileread(filename)
dim objfso, objcountfile, filetempdata
set objfso = server.createobject("scripting.filesystemobject")
set objcountfile = objfso.opentextfile(server.mappath(filename), 1, true)
fsofileread = objcountfile.readall
objcountfile.close
set objcountfile = nothing
set objfso = nothing
end function
%>
18.使用fso读取文件某一行的函数
<%
function fsolinedit(filename, linenum)
if linenum < 1 then exit function
dim fso, f, temparray, tempcnt
set fso = server.createobject("scripting.filesystemobject")
if not fso.fileexists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename), 1)
if not f.atendofstream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt, chr(13)&chr(10))
if linenum>ubound(temparray) + 1 then
exit function
else
fsolinedit = temparray(linenum -1)
end if
end if
end function
%>
19.使用fso写文件某一行的函数
<%
function fsolinewrite(filename, linenum, linecontent)
if linenum < 1 then exit function
dim fso, f, temparray, tempcnt
set fso = server.createobject("scripting.filesystemobject")
if not fso.fileexists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename), 1)
if not f.atendofstream then
tempcnt = f.readall
f.close
temparray = split(tempcnt, chr(13)&chr(10))
if linenum>ubound(temparray) + 1 then
exit function
else
temparray(linenum -1) = linecontent
end if
tempcnt = join(temparray, chr(13)&chr(10))
set f = fso.createtextfile(server.mappath(filename), true)
f.write tempcnt
end if
f.close
set f = nothing
end function
%>
20.使用fso添加文件新行的函数
<%
function fsoappline(filename, linecontent)
dim fso, f
set fso = server.createobject("scripting.filesystemobject")
if not fso.fileexists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename), 8, 1)
f.write chr(13)&chr(10)&linecontent
f.close
set f = nothing
end function
%>
21.读文件最后一行的函数
<%
function fsolastline(filename)
dim fso, f, temparray, tempcnt
set fso = server.createobject("scripting.filesystemobject")
if not fso.fileexists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename), 1)
if not f.atendofstream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt, chr(13)&chr(10))
fsolastline = temparray(ubound(temparray))
end if
end function
%>
利用fso取得bmp,jpg,png,gif文件信息(大小,宽、高等)
<%
'::: bmp, gif, jpg and png :::
'::: this function gets a specified number of bytes from any :::
'::: file, starting at the offset (base 1) :::
'::: :::
'::: passed: :::
'::: flnm => filespec of file to read :::
'::: offset => offset at which to start reading :::
'::: bytes => how many bytes to read :::
'::: :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function getbytes(flnm, offset, bytes)
dim objfso
dim objftemp
dim objtextstream
dim lngsize
on error resume next
set objfso = createobject("scripting.filesystemobject")
' first, we get the filesize
set objftemp = objfso.getfile(flnm)
lngsize = objftemp.size
set objftemp = nothing
fsoforreading = 1
set objtextstream = objfso.opentextfile(flnm, fsoforreading)
if offset > 0 then
strbuff = objtextstream.read(offset - 1)
end if
if bytes = -1 then ' get all!
getbytes = objtextstream.read(lngsize) 'readall
else
getbytes = objtextstream.read(bytes)
end if
objtextstream.close
set objtextstream = nothing
set objfso = nothing
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: :::
'::: functions to convert two bytes to a numeric value (long) :::
'::: (both little-endian and big-endian) :::
'::: :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function lngconvert(strtemp)
lngconvert = clng(asc(left(strtemp, 1)) + ((asc(right(strtemp, 1)) * 256)))
end function
function lngconvert2(strtemp)
lngconvert2 = clng(asc(right(strtemp, 1)) + ((asc(left(strtemp, 1)) * 256)))
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: :::
'::: this function does most of the real work. it will attempt :::
'::: to read any file, regardless of the extension, and will :::
'::: identify if it is a graphical image. :::
'::: :::
'::: passed: :::
'::: flnm => filespec of file to read :::
'::: width => width of image :::
'::: height => height of image :::
'::: depth => color depth (in number of colors) :::
'::: strimagetype=> type of image (e.g. gif, bmp, etc.) :::
'::: :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function gfxspex(flnm, width, height, depth, strimagetype)
dim strpng
dim strgif
dim strbmp
dim strtype
strtype = ""
strimagetype = "(unknown)"
gfxspex = false
strpng = chr(137) & chr(80) & chr(78)
strgif = "gif"
strbmp = chr(66) & chr(77)
strtype = getbytes(flnm, 0, 3)
if strtype = strgif then ' is gif
strimagetype = "gif"
width = lngconvert(getbytes(flnm, 7, 2))
height = lngconvert(getbytes(flnm, 9, 2))
depth = 2 ^ ((asc(getbytes(flnm, 11, 1)) and 7) + 1)
gfxspex = true
elseif left(strtype, 2) = strbmp then ' is bmp
strimagetype = "bmp"
width = lngconvert(getbytes(flnm, 19, 2))
height = lngconvert(getbytes(flnm, 23, 2))
depth = 2 ^ (asc(getbytes(flnm, 29, 1)))
gfxspex = true
elseif strtype = strpng then ' is png
strimagetype = "png"
width = lngconvert2(getbytes(flnm, 19, 2))
height = lngconvert2(getbytes(flnm, 23, 2))
depth = getbytes(flnm, 25, 2)
select case asc(right(depth, 1))
case 0
depth = 2 ^ (asc(left(depth, 1)))
gfxspex = true
case 2
depth = 2 ^ (asc(left(depth, 1)) * 3)
gfxspex = true
case 3
depth = 2 ^ (asc(left(depth, 1))) '8
gfxspex = true
case 4
depth = 2 ^ (asc(left(depth, 1)) * 2)
gfxspex = true
case 6
depth = 2 ^ (asc(left(depth, 1)) * 4)
gfxspex = true
case else
depth = -1
end select
else
strbuff = getbytes(flnm, 0, -1) ' get all bytes from file
lngsize = len(strbuff)
flgfound = 0
strtarget = chr(255) & chr(216) & chr(255)
flgfound = instr(strbuff, strtarget)
if flgfound = 0 then
exit function
end if
strimagetype = "jpg"
lngpos = flgfound + 2
exitloop = false
do while exitloop = false and lngpos < lngsize
do while asc(mid(strbuff, lngpos, 1)) = 255 and lngpos < lngsize
lngpos = lngpos + 1
loop
if asc(mid(strbuff, lngpos, 1)) < 192 or asc(mid(strbuff, lngpos, 1)) > 195 then
lngmarkersize = lngconvert2(mid(strbuff, lngpos + 1, 2))
lngpos = lngpos + lngmarkersize + 1
else
exitloop = true
end if
loop
'
if exitloop = false then
width = -1
height = -1
depth = -1
else
height = lngconvert2(mid(strbuff, lngpos + 4, 2))
width = lngconvert2(mid(strbuff, lngpos + 6, 2))
depth = 2 ^ (asc(mid(strbuff, lngpos + 8, 1)) * 8)
gfxspex = true
end if
end if
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: test harness :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' to test, we'll just try to show all files with a .gif extension in the root of c:
set objfso = createobject("scripting.filesystemobject")
set objf = objfso.getfolder("c:\")
set objfc = objf.files
response.write "<table border=""0"" cellpadding=""5"">"
for each f1 in objfc
if instr(ucase(f1.name), ".gif") then
response.write "<tr><td>" & f1.name & "</td><td>" & f1.datecreated & "</td><td>" & f1.size & "</td><td>"
if gfxspex(f1.path, w, h, c, strtype) = true then
response.write w & " x " & h & " " & c & " colors"
else
response.write " "
end if
response.write "</td></tr>"
end if
next
response.write "</table>"
set objfc = nothing
set objf = nothing
set objfso = nothing
%>
24.点击返回上页代码:
<form>
<p><input type="button" value="返回上一步" onclick="history.back(-1)"></p>
</form>
24.点击刷新代码:
<form>
<p><input type="button" value="刷新按钮一" onclick="reloadbutton()"></p>
</form>
<script language="javascript"><!--
function reloadbutton(){location.href="allbutton.htm";}
// --></script>
24.点击刷新代码2:
<form>
<p><input type="button" value="刷新按钮二" onclick="history.go(0)"> </p>
</form>
<form>
<p><input type="button" value="打开一个网站" onclick="homebutton()"></p>
</form>
<script language="javascript"><!--
function homebutton(){location.href="http://nettrain.126.com";;;}
// --></script>
25.弹出警告框代码:
<form>
<p><input type="button" value="弹出警告框" onclick="alertbutton()"></p>
</form>
<script language="javascript"><!--
function alertbutton(){window.alert("要多多光临呀!");}
// --></script>
26.状态栏信息
<form>
<p><input type="button" value="状态栏信息" onclick="statusbutton()"></p>
</form>
<script language="javascript"><!--
function statusbutton(){window.status="要多多光临呀!";}
// --></script>
27.背景色变换
<form>
<p><input type="button" value="背景色变换" onclick="bgbutton()"></p>
</form>
<script>function bgbutton(){
if (document.bgcolor=='#00ffff')
{document.bgcolor='#ffffff';}
else{document.bgcolor='#00ffff';}
}
</script>
28.点击打开新窗口
<form>
<p><input type="button" value="打开新窗口" onclick="newwindow()"></p>
</form>
<script language="javascript"><!--
function newwindow(){window.open("http://www.mcmx.com";;,"","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");}
// --></script></body>
29.分页代码:
<%''本程序文件名为:pages.asp%>
<%''包含ado常量表文件adovbs.inc,可从"\program files\common files\system\ado"目录下拷贝%>
<!--#include file="adovbs.inc"-->
<%''*建立数据库连接,这里是oracle8.05数据库
set conn = server.createobject("adodb.connection")
conn.open "provider=msdaora.1;data source=yoursrcname;user id=youruserid;password=yourpassword;"
set rs = server.createobject("adodb.recordset") ''创建recordset对象
rs.cursorlocation = aduseclient ''设定记录集指针属性
''*设定一页内的记录总数,可根据需要进行调整
rs.pagesize = 10
''*设置查询语句
strsql = "select id,姓名,住址,电话 from 通讯录 order by id"
rs.open strsql, conn, adopenstatic, adlockreadonly, adcmdtext
%>
<html>
<head>
<title>分页示例</title>
<script language=javascript>
//点击"[第一页]"时响应:
function pagefirst()
{
document.myform.currentpage.selectedindex=0;
document.myform.currentpage.onchange();
}
//点击"[上一页]"时响应:
function pageprior()
{
document.myform.currentpage.selectedindex--;
document.myform.currentpage.onchange();
}
//点击"[下一页]"时响应:
function pagenext()
{
document.myform.currentpage.selectedindex++;
document.myform.currentpage.onchange();
}
//点击"[最后一页]"时响应:
function pagelast()
{
document.myform.currentpage.selectedindex=document.myform.currentpage.length-1;
document.myform.currentpage.onchange();
}
//选择"第?页"时响应:
function pagecurrent()
{ //pages.asp是本程序的文件名
document.myform.action='pages.asp?page='+(document.myform.currentpage.selectedindex+1)
document.myform.submit();
}
</script>
</head>
<body bgcolor="#ffffcc" link="#008000" vlink="#008000" alink="#ff0000"">
<%
if rs.eof then
response.write("<font size=2 color=#000080>[数据库中没有记录!]</font>")
else
''指定当前页码
if request("currentpage") = "" then
rs.absolutepage = 1
else
rs.absolutepage = clng(request("currentpage"))
end if
''创建表单myform,方法为get
response.write("<form method=get name=myform>")
response.write("<p align=center><font size=2 color=#008000>")
''设置翻页超链接
if rs.pagecount = 1 then
response.write("[第一页] [上一页] [下一页] [最后一页] ")
else
if rs.absolutepage = 1 then
response.write("[第一页] [上一页] ")
response.write("[<a href=java script:pagenext()>下一页</a>] ")
response.write("[<a href=java script:pagelast()>最后一页</a>] ")
else
if rs.absolutepage = rs.pagecount then
response.write("[<a href=java script:pagefirst()>第一页</a>] ")
response.write("[<a href=java script:pageprior()>上一页</a>] ")
response.write("[下一页] [最后一页] ")
else
response.write("[<a href=java script:pagefirst()>第一页</a>] ")
response.write("[<a href=java script:pageprior()>上一页</a>] ")
response.write("[<a href=java script:pagenext()>下一页</a>] ")
response.write("[<a href=java script:pagelast()>最后一页</a>] ")
end if
end if
end if
''创建下拉列表框,用于选择浏览页码
response.write("第<select size=1 name=currentpage onchange=pagecurrent()>")
for i = 1 to rs.pagecount
if rs.absolutepage = i then
response.write("<option selected>"&i&"</option>") ''当前页码
else
response.write("<option>"&i&"</option>")
end if
next
response.write("</select>页/共"&rs.pagecount&"页 共"&rs.recordcount&"条记录</font><p>")
response.write("</form>")
''创建表格,用于显示
response.write("<table align=center cellspacing=1 cellpadding=1 border=1")
response.write(" bordercolor=#99ccff bordercolordark=#b0e0e6 bordercolorlight=#000066>")
response.write("<tr bgcolor=#ccccff bordercolor=#000066>")
set columns = rs.fields
''显示表头
for i = 0 to columns.count -1
response.write("<td align=center width=200 height=13>")
response.write("<font size=2><b>"&columns(i).name&"</b></font></td>")
next
response.write("</tr>")
''显示内容
for i = 1 to rs.pagesize
response.write("<tr bgcolor=#99ccff bordercolor=#000066>")
for j = 0 to columns.count -1
response.write("<td><font size=2>"&columns(j)&"</font></td>")
next
response.write("</tr>")
rs.movenext
if rs.eof then exit for
next
response.write("</table>")
end if
%>
</body>
</html>
<%
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
%>
<%
'定义超全局变量
dim urlself, uriself
uriself = request.servervariables("script_name")
if request.querystring = "" then
urlself = uriself
else
urlself = uriself & "?" & request.querystring
end if
response.charset = "gb2312"
response.buffer = true
response.expires = -1
'===================================================================================
' 函数原型:gotourl (url)
'功能:转到指定的url
'参数:url 要跳转的url
'返 回 值:无
'涉及的表:无
'===================================================================================
public function gotourl(url)
response.write "<script language=""javascript"">location.href='" & url & "';</script>"
end function
'===================================================================================
' 函数原型:messagebox (msg)
'功能:显示消息框
'参数:要显示的消息
'返 回 值:无
'涉及的表:无
'===================================================================================
public function messagebox(msg)
msg = replace(msg, "\", "\\")
msg = replace(msg, "'", "\'")
msg = replace(msg, """", "\""")
msg = replace(msg, vbcrlf, "\n")
msg = replace(msg, vbcr, "")
msg = replace(msg, vblf, "")
response.write "<script language=""javascript"">alert('" & msg & "');</script>"
end function
'===================================================================================
' 函数原型:returnvalue (bolvalue)
'功能:设置window对象的返回值:只能是布尔值
'参数:返回值
'返 回 值:无
'涉及的表:无
'===================================================================================
public function returnvalue(bolvalue)
if bolvalue then
response.write "<script language=""javascript"">window.returnvalue=true;</script>"
else
response.write "<script language=""javascript"">window.returnvalue=false;</script>"
end if
end function
'===================================================================================
' 函数原型:goback (url)
'功能:后退
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function goback()
response.write "<script language=""javascript"">history.go(-1);</script>"
end function
'===================================================================================
' 函数原型:closewindow ()
'功能:关闭窗口
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function closewindow()
response.write "<script language=""javascript"">window.opener=null;window.close();</script>"
end function
'===================================================================================
' 函数原型:refreshparent ()
'功能:刷新父框架
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function refreshparent()
response.write "<script language=""javascript"">if(parent!=self) parent.location.reload();</script>"
end function
'===================================================================================
' 函数原型:refreshtop ()
'功能:刷新*框架
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function refreshtop()
response.write "<script language=""javascript"">if(top!=self) top.location.reload();</script>"
end function
'===================================================================================
' 函数原型:genpassword (intlen,passmask)
'功能:生成随机密码
'参数:intlen新密码长度
'passmask生成密码的掩码默认为空
'返 回 值:无
'涉及的表:无
'===================================================================================
public function genpassword(intlen, passmask)
dim icnt, postemp
randomize
if passmask = "" then
passmask = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz"
end if
for icnt = 1 to intlen
postemp = fix(rnd(1) * (len(passmask))) + 1
genpassword = genpassword & mid(passmask, postemp, 1)
next
end function
'===================================================================================
' 函数原型:genserialstring ()
'功能:生成序列号
'参数:无
'返 回 值:无
'涉及的表:无
'===================================================================================
public function genserialstring()
genserialstring = year(now())
if month(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & month(now())
if day(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & day(now())
if hour(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & hour(now())
if minute(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & minute(now())
if second(now())<10 then
genserialstring = genserialstring & "0"
end if
genserialstring = genserialstring & second(now())
genserialstring = genserialstring & genpassword(6, "0123456789abcdefghijklmnopqrstuvwxyz")
end function
'===================================================================================
' 函数原型:changepage(urltemplete,pageindex)
'功能:根据url模板生成新的页面url
'参数:urltempleteurl模板
' pageindex新的页码
'返 回 值:生成的url
'涉及的表:无
'===================================================================================
public function changepage(urltemplete, pageindex)
changepage = setquerystring(urltemplete, "page", pageindex)
end function
'===================================================================================
' 函数原型:buildpath(spath)
'功能:根据指定的路径创建目录
'参数:spathurl模板
'返 回 值:如果成功,返回空字符串,否则返回错误信息和错误位置
'涉及的表:无
'===================================================================================
public function buildpath (spath)
dim icnt
dim path
dim basepath
path = split(spath, "/")
if left(spath, 1) = "/" or left(spath, 1) = "\" then
basepath = server.mappath("/")
else
basepath = server.mappath(".")
end if
dim cpath, ofso
cpath = basepath
buildpath = ""
set ofso = server.createobject("scripting.filesystemobject")
for icnt = lbound(path) to ubound(path)
if trim(path(icnt))<>"" then
cpath = cpath & "\" & trim(path(icnt))
if not ofso.folderexists(cpath) then
on error resume next
ofso.createfolder cpath
if err.number<>0 then
buildpath = err.description & "[" & cpath & "]"
exit for
end if
on error goto 0
end if
end if
next
set ofso = nothing
end function
'===================================================================================
' 函数原型:getuseragentinfo(byref vsoft,byref vos)
'功能:获取客户端操作系统和浏览器信息
'参数:vsoft浏览器信息
'vos操作系统信息
'返 回 值:无
'涉及的表:无
'===================================================================================
public function getuseragentinfo(byref vsoft, byref vos)
dim thesoft
thesoft = request.servervariables("http_user_agent")
' 浏览器
if instr(thesoft, "netcaptor") then
vsoft = "netcaptor"
elseif instr(thesoft, "msie 6") then
vsoft = "msie 6.0"
elseif instr(thesoft, "msie 5.5+") then
vsoft = "msie 5.5"
elseif instr(thesoft, "msie 5") then
vsoft = "msie 5.0"
elseif instr(thesoft, "msie 4") then
vsoft = "msie 4.0"
elseif instr(thesoft, "netscape") then
vsoft = "netscape"
elseif instr(thesoft, "opera") then
vsoft = "opera"
else
vsoft = "other"
end if
' 操作系统
if instr(thesoft, "windows nt 5.0") then
vos = "windows 2000"
elseif instr(thesoft, "windows nt 5.1") then
vos = "windows xp"
elseif instr(thesoft, "windows nt 5.2") then
vos = "windows 2003"
elseif instr(thesoft, "windows nt") then
vos = "windows nt"
elseif instr(thesoft, "windows 9") then
vos = "windows 9x"
elseif instr(thesoft, "unix") then
vos = "unix"
elseif instr(thesoft, "linux") then
vos = "linux"
elseif instr(thesoft, "sunos") then
vos = "sunos"
elseif instr(thesoft, "bsd") then
vos = "bsd"
elseif instr(thesoft, "mac") then
vos = "mac"
else
vos = "other"
end if
end function
'===================================================================================
' 函数原型:getregexpobject()
'功能:获得一个正则表达式对象
'参数:无
'返 回 值:正则表达式对象
'涉及的表:无
'===================================================================================
public function getregexpobject(spattern)
dim r
set r = new regexp
r.global = true
r.ignorecase = true
r.multiline = true
r.pattern = spattern
set getregexpobject = r
set r = nothing
end function
'===================================================================================
' 函数原型:regexptest(pattern,string)
'功能:正则表达式检测
'参数:pattern模式字符串
'string待检查的字符串
'返 回 值:是否匹配
'涉及的表:无
'===================================================================================
public function regexptest(p, s)
dim r
set r = getregexpobject(p)
regexptest = r.test(s)
set r = nothing
end function
'===================================================================================
' 函数原型:regexpreplace(ssource,spattern,srep)
'功能:正则表达式替换
'参数:ssource要替换的源字符串
'spattern模式字符串
'srep要替换的目标字符串
'返 回 值:替换后的字符串
'涉及的表:无
'===================================================================================
public function regexpreplace(ssource, spattern, srep)
dim r
set r = getregexptest(spattern)
regexpreplace = r.replace(ssource, srep)
set r = nothing
end function
'===================================================================================
' 函数原型:createxmlparser()
'功能:创建一个尽可能高版本的xmldom
'参数:无
'返 回 值:idomdocument对象
'涉及的表:无
'===================================================================================
public function createxmlparser()
on error resume next
set createxmlparser = server.createobject("msxml2.domdocument.4.0")
if err.number<>0 then
err.clear
set createxmlparser = server.createobject("msxml2.domdocument.3.0")
if err.number<>0 then
err.clear
set createxmlparser = server.createobject("msxml2.domdocument.2.6")
if err.number<>0 then
err.clear
set createxmlparser = server.createobject("msxml2.domdocument")
if err.number<>0 then
err.clear
set createxmlparser = server.createobject("microsoft.xmldom")
if err.number<>0 then
err.clear
set createxmlparser = nothing
else
exit function
end if
else
exit function
end if
else
exit function
end if
else
exit function
end if
else
exit function
end if
on error goto 0
end function
'===================================================================================
' 函数原型:createhttpposter()
'功能:创建一个尽可能高版本的xmlhttp
'参数:serverorclient创建serverxmlhttp还是xmlhttp
'返 回 值:ixmlhttp对象
'涉及的表:无
'===================================================================================
public function createhttpposter(soc)
dim s
if soc then
s = "serverxmlhttp"
else
s = "xmlhttp"
end if
on error resume next
set createhttpposter = server.createobject("msxml2." & s & ".4.0")
if err.number<>0 then
err.clear
set createhttpposter = server.createobject("msxml2." & s & ".3.0")
if err.number<>0 then
err.clear
set createhttpposter = server.createobject("msxml2." & s)
if err.number<>0 then
set createhttpposter = nothing
else
exit function
end if
else
exit function
end if
else
exit function
end if
on error goto 0
end function
'===================================================================================
' 函数原型:xmlthrowerror (errcode,errreason)
'功能:抛出一个xml错误消息
'参数:errcode错误编码
'errreason错误原因
'返 回 值:无
'涉及的表:无
'===================================================================================
public sub xmlthrowerror (errcode, errreason)
response.clear
response.contenttype = "text/xml"
response.write"<?xml version=""1.0"" encoding=""gb2312"" standalone=""yes"" ?>" & vbcrlf & _
"<error code=""" & errcode & """ reason=""" & errreason & """ />" & vbcrlf
response.flush
response.end
end sub
'===================================================================================
' 函数原型:getxmlnodevalue(byref xmldom,sfilter,sdefvalue)
'功能:从一个xml文档中查找指定节点的值
'参数:xmldomxml文档
'sfilterxpath定位字符串
'sdefvalue默认值
'返 回 值:无
'涉及的表:无
'===================================================================================
public function getxmlnodevalue(byref xmldom, sfilter, sdefvalue)
dim onode
set onode = xmldom.selectsinglenode(sfilter)
if typename(onode) = "nothing" or typename(onode) = "null" or typename(onode) = "empty" then
getxmlnodevalue = sdefvalue
set onode = nothing
else
getxmlnodevalue = trim(onode.text)
set onode = nothing
end if
end function
'===================================================================================
' 函数原型:getxmlnodeattribute(byref xmldom,sfilter,sname,sdefvalue)
'功能:从一个xml文档中查找指定节点的指定属性
'参数:xmldomxml文档
'sfilterxpath定位字符串
'sname要查询的属性名称
'sdefvalue默认值
'返 回 值:无
'涉及的表:无
'===================================================================================
public function getxmlnodeattribute(byref xmldom, sfilter, sname, sdefvalue)
dim onode
set onode = xmldom.selectsinglenode(sfilter)
if typename(onode) = "nothing" or typename(onode) = "null" or typename(onode) = "empty" then
getxmlnodeattribute = sdefvalue
set onode = nothing
else
dim ptemp
set ptemp = onode.getattribute(sname)
if typename(ptemp) = "nothing" or typename(ptemp) = "null" or typename(ptemp) = "empty" then
getxmlnodeattribute = sdefvalue
set onode = nothing
set ptemp = nothing
else
getxmlnodeattribute = trim(ptemp.value)
set onode = nothing
set ptemp = nothing
end if
end if
end function
'===================================================================================
' 函数原型:getquerystringnumber (fieldname,defvalue)
'功能:从querystring获取一个整数
'参数:fieldname参数名
'defvalue默认值
'返 回 值:无
'涉及的表:无
'===================================================================================
public function getquerystringnumber (fieldname, defvalue)
dim r
r = request.querystring(fieldname)
if r = "" then
getquerystringnumber = defvalue
exit function
else
if not isnumeric(r) then
getquerystringnumber = defvalue
exit function
else
on error resume next
r = cdbl(r)
if err.number<>0 then
err.clear
getquerystringnumber = defvalue
exit function
else
getquerystringnumber = r
end if
on error goto 0
end if
end if
end function
'===================================================================================
' 函数原型:iif (testexpr,value1,value2)
'功能:相当于c/c++里面的 ?: 运算符
'参数:testexprboolean表达式
'value1testexpr=true 时的取值
'value2testexpr=false 时的取值
'返 回 值:如果testexpr为true返回value1否则返回value2
'涉及的表:无
'说明:vbscript里没有iif函数
'===================================================================================
public function iif(testexpr, value1, value2)
if testexpr = true then
iif = value1
else
iif = value2
end if
end function
'===================================================================================
' 函数原型:urlencoding (v,f)
'功能:url编码函数
'参数:v中英文混合字符串
'f是否对ascii字符编码
'返 回 值:编码后的asc字符串
'涉及的表:无
'===================================================================================
public function urlencoding(v, f)
dim s, t, i, j, h, l, x
s = ""
x = len(v)
for i = 1 to x
t = mid(v, i, 1)
j = asc(t)
if j> 0 then
if f then
s = s & "%" & right("00" & hex(asc(t)), 2)
else
s = s & t
end if
else
if j < 0 then j = j + &h10000
h = (j and &hff00) \ &hff
l = j and &hff
s = s & "%" & hex(h) & "%" & hex(l)
end if
next
urlencoding = s
end function
'===================================================================================
' 函数原型:urldecoding (sin)
'功能:url解码码函数
'参数:vurl编码的字符串
'返 回 值:解码后的字符串
'涉及的表:无
'===================================================================================
public function urldecoding(sin)
dim s, i, l, c, t, n
s = ""
l = len(sin)
for i = 1 to l
c = mid(sin, i, 1)
if c<>"%" then
s = s & c
else
c = mid(sin, i + 1, 2)
i = i + 2
t = cint("&h" & c)
if t<&h80 then
s = s & chr(t)
else
c = mid(sin, i + 1, 3)
if left(c, 1)<>"%" then
urldecoding = s
exit function
else
c = right(c, 2)
n = cint("&h" & c)
t = t * 256 + n -65536
s = s & chr(t)
i = i + 3
end if
end if
end if
next
urldecoding = s
end function
'===================================================================================
' 函数原型:bytes2bstr (v)
'功能:utf-8编码转换到正常的gb2312
'参数:vutf-8编码字节流
'返 回 值:解码后的字符串
'涉及的表:无
'===================================================================================
public function bytes2bstr(v)
dim r, i, t, n
r = ""
for i = 1 to lenb(v)
t = ascb(midb(v, i, 1))
if t < &h80 then
r = r & chr(t)
else
n = ascb(midb(v, i + 1, 1))
r = r & chr(clng(t) * &h100 + cint(n))
i = i + 1
end if
next
bytes2bstr = r
end function
%>
上一篇: Java调用SQL脚本执行常用的方法示例
下一篇: php Calender(日历)代码分享