欢迎光临
我们一直在努力

面向对象的asp编程之八—服务器端函数-ASP教程,脚本编码

建站超值云服务器,限时71元/月

<script language="vbscript" runat="server">

****************************************************************

script compont object model

design for active server pages

copyright 2004 version 2.0

made by 尹曙光

all rights reserved.

****************************************************************

系统常用的一些公用函数

*****************************************************************

系统公用信息显示

strmsg:提示信息

msgtype:信息提示类型

jumpurl:页面眺转地址

strcopyright:版权信息

function fshowmsg(strmsg,msgtype,jumpurl,strcopyright)

response.write "<style>"&chr(13)

response.write "body { margin: 0px 0px 0px 0px;font-family: 宋体,tahoma, ms shell dlg;color: #000000;font: 9pt;background-color:#f0f1eb;}"&chr(13)

response.write "a{font:normal 12px 宋体;color: #336699; text-decoration: none}"&chr(13)

response.write "td{font-family:宋体; font-size: 12px; line-height: 15px;background-color:#f0f1eb;}"&chr(13)

response.write ".thead{ background-color: #336699;color:#ffffff;font-weight:bold;}"&chr(13)

response.write ".tfoot{ background-color: #336699;color: #ffffff;}"&chr(13)

response.write "</style>"&chr(13)

response.write "<table height=90% width=100%> <tr>"&chr(13)

response.write "<td align=center> <table align=center cellpadding=0 cellspacing=0 bordercolor=#336699 bgcolor=#336699 style=width:90%>"

response.write "<tr align=center>"&chr(13)

response.write "<td width=100% height=20 colspan=2 bgcolor=#336699 class=thead >系统提示信息</t> "&chr(13)

response.write "<tr><td width=100% colspan=2 align=center bgcolor=#ffffff><br> "&chr(13)

response.write strmsg

select case cint(msgtype)

case 1

response.write "[<a href=javascript:window.close();>关闭窗口</a>]"

case 2

response.write "[<a href=javascript:history.back(-1);>返回</a>]"

case 3

response.write "[<a href=javascript:history.back("&jumpurl&");>返回</a>]"

case 4

response.write "<meta http-equiv=refresh content=3; url="&jumpurl&">,正在跳转…"

case 5

response.write "[<a href="&jumpurl&">返回</a>]"

end select

response.write "<br><br></td></tr><tr align=center><td width=100% height=20 colspan=2 class=tfoot>"&chr(13)

response.write strcopyright

response.write "</td> </tr></table></td> </tr> </table>"&chr(13)

response.end()

end function

检查系统错误

errmsg:出错后的提示信息

function fiferror(errmsg)

if err.number>0 then

response.write "<br>"

response.write errmsg

response.end

end if

end function

显示系统错误信息

function fsystemerror()

if err.number>0 then

response.write "<br>"

response.write "错误来源:"&err.source&"<br>"

response.write "错误代码:"&err.number&"<br>"

response.write "错误说明:"&err.description &"<br>"

response.end

end if

end function

判断是不是从form提交过来的

function fispostback()

if ( ucase(trim(request.servervariables("request_method")))="post") then

fispostback=true

else

fispostback=false

end if

end function

function fgetuserip()

fgetuserip=request.servervariables("remote_addr")

end function

</script>

<script language="vbscript" runat="server">

****************************************************************

script compont object model

design for active server pages

copyright 2004 version 2.0

made by 尹曙光

all rights reserved.

****************************************************************

字符串处理函数

*****************************************************************

取得一个长度为ilen的字符串,含字母和数字

function frandomstr(ilen)

dim c,strresult

ilen=cint(ilen)

for i=1 to ilen

randomize

c=int((74 * rnd) + 48) c>48 and c<122

while (c>57 and c<65) or (c>90 and c<97)

randomize

c=int((74 * rnd) + 48)

wend

strresult=strresult&cstr(chr(c))

next

frandomstr=strresult

end function

以下两个函数是用于检查身份证件号的

function fcheckidcard2(stridcard)

dim iidcard,strtmp

iidcard=len(stridcard)

if (iidcard=null or (not(iidcard=15 or iidcard=18))) then

fcheckidcard2=false

exit function

end if

if iidcard=15 then

strtmp=stridcard

else

strtmp=mid(stridcard,1,17)

end if

if isnumeric(strtmp) then

fcheckidcard2=true

else

fcheckidcard2=false

exit function

end if

if iidcard=18 then

strtmp=mid(stridcard,18,1)

strtmp=ucase(strtmp)

if not (isnumeric(strtmp) or strtmp="x") then

fcheckidcard2=false

exit function

end if

end if

end function

检查身份证号

参数:str:待检查的字符串

参数2:出生日期的年(4位)

参数3:出生日期的月

参数4:出生日期的日

function fcheckidcard(byval stridcard,byval iyear,byval imonth,byval iday)

dim strbirthday,strtmp1

if not fcheckidcard2(stridcard) then

fcheckidcard=false

exit function

end if

if len(iyear)<>4 then

fcheckidcard=false

exit function

end if

strbirthday=cstr(iyear)+string(2-len(cstr(imonth)),"0")+cstr(imonth)+string(2-len(cstr(iday)),"0")+cstr(iday)

if len(stridcard)=15 then

strtmp1=mid(stridcard,7,6)

strbirthday=mid(strbirthday,3,6)

if strtmp1<>strbirthday then

fcheckidcard=false

exit function

end if

else

strtmp1=mid(stridcard,7,8)

if strtmp1<>strbirthday then

fcheckidcard=false

exit function

end if

end if

fcheckidcard=true

end function

检查邮编

function fcheckpostcode(byval strcode)

if (len(trim(strcode))<>6) then

fcheckpostcode=false

exit function

else

fcheckpostcode=isnumeric(strcode)

exit function

end if

end function

—————–可逆加密———————————————-

function encrypt(byval ecode)

dim texts

dim i

for i=1 to len(ecode)

texts=texts & chr(asc(mid(ecode,i,1))+i)

next

encrypt = texts

end function

function decrypt(byval dcode)

dim texts

dim i

for i=1 to len(dcode)

texts=texts & chr(asc(mid(dcode,i,1))-i)

next

decrypt=texts

end function

—————-不可逆加密—————————————————

function mistake(byval prestring)

dim texts

dim seed

dim i,length

prestring = trim(prestring)

length = len(prestring)

seed = length

randomize(length)

texts = ""

for i = 1 to length

seed = int(94*rnd(-asc(mid(prestring,i,1))-seed*asc(right(prestring,1)))+32)

texts = texts & chr(seed) & chr(int(94*rnd(-seed)+32))

next

dim dist

dist=""

for i = 1 to len(texts)

if mid(texts,i,1)<>"" then

dist=dist+mid(texts,i,1)

end if

next

mistake = dist

end function

</script>

<script language=javascript runat=server>

// ************************************************************************

// script compont object model

// design for active server pages

//

// copyright 2003 version 1.0

// made by 尹曙光

// ************************************************************************

function getarrayorder(amain,str){ //数组,给定其数值,求其在数组的下标

//amain为数组,str为数组中的内容

var imain=-1

if ((amain.length==0)||(str.length==0)){

return imain

}

for(var i=0;i<amain.length;i++){

if (amain[i]==str) {

imain=i

break;

}

}

return imain

}

function getarrayorders(amain,str){ //数组,给定其数值,求其在数组的下标

//该函数返回树组,依次列出,值在数组中的下标

//amain为数组,str为数组中的内容

thisresult=new array

thisresult[0]=-1

if ((amain.length==0)||(str.length==0)){

return thisresult

}

var j=0;

for(var i=0;i<amain.length;i++){

if (amain[i]==str) {

thisresult[j++]=i

}

}

return thisresult

}

</script>

<script language=jscript runat=server>

// ************************************************************************

// script compont object model

// design for active server pages

//

// copyright 2003 version 1.0

// made by 尹曙光

// ************************************************************************

function saverstotxtfile(rs,filename)

{

//将recordset的内容保存进一个txt文件中,rs数据集,filename文件的绝对路径

var fs = server.createobject("scripting.filesystemobject")

if (fs.fileexists(filename))

fs.deletefile(filename)

var txtfile = fs.createtextfile(filename)

var strline=""

//写入字段名

var nfields = rs.fields.count;

for (var i=0; i < nfields; i++)

strline+= rs(i).name+"\t"

txtfile.writeline(strline)

//写入内容

while (! rs.eof ){

strline=""

for (var i=0; i < nfields; i++)

strline+= rs(i).value+"\t"

txtfile.writeline(strline)

rs.movenext()

}

txtfile= null

fs=null

}

</script>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 面向对象的asp编程之八—服务器端函数-ASP教程,脚本编码
分享到: 更多 (0)

相关推荐

  • 暂无文章