信息系统项目管理师_2024年软考学习应考交流_信息系统项目管理师考试

 找回密码
 马上注册

QQ登录

只需一步,快速开始

楼主: 翔羽
打印 上一主题 下一主题

[转帖]ASP编程常用的代码

  [复制链接]

该用户从未签到

升级  30.8%

61
 楼主| 发表于 2006-2-24 09:24:04 | 只看该作者
&lt;% <br/>Dim Image <br/>Dim Width, Height <br/>Dim num <br/>Dim digtal <br/>Dim Length <br/>Dim sort <br/>Length = 4 '自定计数器长度 <p>Redim sort( Length ) </p><p>num=cint(DeCryptString(request.querystring("sksid"))) <br/>digital = "" <br/>For I = 1 To Length -Len( num ) '补0 <br/>digital = digital &amp; "0" <br/>Next <br/>For I = 1 To Len( num ) <br/>digital = digital &amp; Mid( num, I, 1 ) <br/>Next <br/>For I = 1 To Len( digital ) <br/>sort(I) = Mid( digital, I, 1 ) <br/>Next <br/>Width = 8 * Len( digital ) '图像的宽度 <br/>Height = 10 '图像的高度,在本例中为固定值 </p><p><br/>Response.ContentType="image/x-xbitmap" </p><p>hc=chr(13) &amp; chr(10) </p><p>Image = "#define counter_width " &amp; Width &amp; hc <br/>Image = Image &amp; "#define counter_height " &amp; Height &amp; hc <br/>Image = Image &amp; "static unsigned char counter_bits[]={" &amp; hc </p><p>For I = 1 To Height <br/>For J = 1 To Length <br/>Image = Image &amp; a(sort(J),I) &amp; "," <br/>Next <br/>Next </p><p>Image = Left( Image, Len( Image ) - 1 ) '去掉最后一个逗号 <br/>Image = Image &amp; "};" &amp; hc <br/>%&gt; <br/>&lt;% <br/>Response.Write Image </p><p>%&gt; </p><p></p><p>numimg.asp </p><p></p><p>&lt;% <br/>Dim a(10,10) </p><p>a(0,1) = "0x3c" '数字0 <br/>a(0,2) = "0x66" <br/>a(0,3) = "0xc3" <br/>a(0,4) = "0xc3" <br/>a(0,5) = "0xc3" <br/>a(0,6) = "0xc3" <br/>a(0,7) = "0xc3" <br/>a(0,8) = "0xc3" <br/>a(0,9) = "0x66" <br/>a(0,10)= "0x3c" </p><p>a(1,1) = "0x18" '数字1 <br/>a(1,2) = "0x1c" <br/>a(1,3) = "0x18" <br/>a(1,4) = "0x18" <br/>a(1,5) = "0x18" <br/>a(1,6) = "0x18" <br/>a(1,7) = "0x18" <br/>a(1,8) = "0x18" <br/>a(1,9) = "0x18" <br/>a(0,10)= "0x7e" </p><p><br/>a(2,1) = "0x3c" '数字2 <br/>a(2,2) = "0x66" <br/>a(2,3) = "0x60" <br/>a(2,4) = "0x60" <br/>a(2,5) = "0x30" <br/>a(2,6) = "0x18" <br/>a(2,7) = "0x0c" <br/>a(2,8) = "0x06" <br/>a(2,9) = "0x06" <br/>a(2,10)= "0x7e" </p><p>a(3,1) = "0x3c" '数字3 <br/>a(3,2) = "0x66" <br/>a(3,3) = "0xc0" <br/>a(3,4) = "0x60" <br/>a(3,5) = "0x1c" <br/>a(3,6) = "0x60" <br/>a(3,7) = "0xc0" <br/>a(3,8) = "0xc0" <br/>a(3,9) = "0x66" <br/>a(3,10)= "0x38" </p><p>a(4,1) = "0x38" '数字4 <br/>a(4,2) = "0x3c" <br/>a(4,3) = "0x36" <br/>a(4,4) = "0x33" <br/>a(4,5) = "0x33" <br/>a(4,6) = "0x33" <br/>a(4,7) = "0xff" <br/>a(4,8) = "0x30" <br/>a(4,9) = "0x30" <br/>a(4,10)= "0xfe" </p><p>a(5,1) = "0xfe" '数字5 <br/>a(5,2) = "0xfe" <br/>a(5,3) = "0x06" <br/>a(5,4) = "0x06" <br/>a(5,5) = "0x3e" <br/>a(5,6) = "0x60" <br/>a(5,7) = "0xc0" <br/>a(5,8) = "0xc3" <br/>a(5,9) = "0x66" <br/>a(5,10)= "0x3c" </p><p>a(6,1) = "0x60" '数字6 <br/>a(6,2) = "0x30" <br/>a(6,3) = "0x18" <br/>a(6,4) = "0x0c" <br/>a(6,5) = "0x3e" <br/>a(6,6) = "0x63" <br/>a(6,7) = "0xc3" <br/>a(6,8) = "0xc3" <br/>a(6,9) = "0x66" <br/>a(6,10) ="0x3c" </p><p>a(7,1) = "0xff" '数字7 <br/>a(7,2) = "0xc0" <br/>a(7,3) = "0x60" <br/>a(7,4) = "0x30" <br/>a(7,5) = "0x18" <br/>a(7,6) = "0x18" <br/>a(7,7) = "0x18" <br/>a(7,8) = "0x18" <br/>a(7,9) = "0x18" <br/>a(7,10)= "0x18" </p><p>a(8,1) = "0x3c" '数字8 <br/>a(8,2) = "0x66" <br/>a(8,3) = "0xc3" <br/>a(8,4) = "0x66" <br/>a(8,5) = "0x3c" <br/>a(8,6) = "0x66" <br/>a(8,7) = "0xc3" <br/>a(8,8) = "0xc3" <br/>a(8,9) = "0x66" <br/>a(8,10)= "0x3c" </p><p>a(9,1) = "0x3c" '数字9 <br/>a(9,2) = "0x66" <br/>a(9,3) = "0xc3" <br/>a(9,4) = "0xc3" <br/>a(9,5) = "0x66" <br/>a(9,6) = "0x3c" <br/>a(9,7) = "0x18" <br/>a(9,8) = "0x0c" <br/>a(9,9) = "0x06" <br/>a(9,10)= "0x03" </p><p>%&gt;<br/></p>

该用户从未签到

升级  30.8%

62
 楼主| 发表于 2006-2-24 09:24:20 | 只看该作者
<strong>分页代码例子<hr/></strong><p><br/>&lt;%''本程序文件名为:Pages.asp%&gt;<br/>&lt;%''包含ADO常量表文件adovbs.inc,可从"\Program Files\Common Files\System\ADO"目录下拷贝%&gt;<br/>&lt;!--#Include File="adovbs.inc"--&gt;<br/>&lt;%''*建立数据库连接,这里是Oracle8.05数据库<br/>Set conn=Server.CreateObject("ADODB.Connection") <br/>conn.Open "rovider=msdaora.1;Data Source=YourSrcName;User ID=YourUserIDassword=YourPassword;" </p><p>Set rs=Server.CreateObject("ADODB.Recordset") ''创建Recordset对象<br/>rs.CursorLocation=adUseClient ''设定记录集指针属性<br/>''*设定一页内的记录总数,可根据需要进行调整 <br/>rs.PageSize=10 </p><p>''*设置查询语句 <br/>StrSQL="Select ID,姓名,住址,电话 from 通讯录 Order By ID" <br/>rs.Open StrSQL,conn,adOpenStatic,adLockReadOnly,adCmdText<br/>%&gt;<br/>&lt;HTML&gt;<br/>&lt;HEAD&gt;<br/>&lt;title&gt;分页示例&lt;/title&gt;<br/>&lt;script language=javascript&gt;<br/>//点击"[第一页]"时响应:<br/>function PageFirst()<br/>{ <br/>document.MyForm.CurrentPage.selectedIndex=0;<br/>document.MyForm.CurrentPage.onchange();<br/>}<br/>//点击"[上一页]"时响应:<br/>function PagePrior()<br/>{ <br/>document.MyForm.CurrentPage.selectedIndex--;<br/>document.MyForm.CurrentPage.onchange();<br/>}<br/>//点击"[下一页]"时响应:<br/>function PageNext()<br/>{ <br/>document.MyForm.CurrentPage.selectedIndex++;<br/>document.MyForm.CurrentPage.onchange(); <br/>}<br/>//点击"[最后一页]"时响应:<br/>function PageLast()<br/>{ <br/>document.MyForm.CurrentPage.selectedIndex=document.MyForm.CurrentPage.length-1;<br/>document.MyForm.CurrentPage.onchange();<br/>}<br/>//选择"第?页"时响应:<br/>function PageCurrent()<br/>{ //Pages.asp是本程序的文件名<br/>document.MyForm.action='Pages.asp?Page='+(document.MyForm.CurrentPage.selectedIndex+1)<br/>document.MyForm.submit();<br/>} <br/>&lt;/Script&gt;<br/>&lt;/HEAD&gt;<br/>&lt;BODY bgcolor="#ffffcc" link="#008000" vlink="#008000" alink="#FF0000""&gt;<br/><br/>&lt;%IF rs.Eof THEN<br/>Response.Write("&lt;font size=2 color=#000080&gt;[数据库中没有记录!]&lt;/font&gt;")<br/>ELSE <br/>''指定当前页码<br/>If Request("CurrentPage")="" Then<br/>rs.AbsolutePage=1<br/>Else<br/>rs.AbsolutePage=CLng(Request("CurrentPage"))<br/>End If <br/><br/>''创建表单MyForm,方法为Get<br/>Response.Write("&lt;form method=Get name=MyForm&gt;") <br/>Response.Write("&lt;p align=center&gt;&lt;font size=2 color=#008000&gt;")<br/>''设置翻页超链接<br/>if rs.PageCount=1 then <br/>Response.Write("[第一页] [上一页] [下一页] [最后一页] ")<br/>else <br/>if rs.AbsolutePage=1 then<br/>Response.Write("[第一页] [上一页] ")<br/>Response.Write("[&lt;a href=javascriptageNext()&gt;下一页&lt;/a&gt;] ") <br/>Response.Write("[&lt;a href=javascriptageLast()&gt;最后一页&lt;/a&gt;] ") <br/>else <br/>if rs.AbsolutePage=rs.PageCount then<br/>Response.Write("[&lt;a href=javascriptageFirst()&gt;第一页&lt;/a&gt;] ") <br/>Response.Write("[&lt;a href=javascriptagePrior()&gt;上一页&lt;/a&gt;] ") <br/>Response.Write("[下一页] [最后一页] ")<br/>else<br/>Response.Write("[&lt;a href=javascriptageFirst()&gt;第一页&lt;/a&gt;] ") <br/>Response.Write("[&lt;a href=javascriptagePrior()&gt;上一页&lt;/a&gt;] ") <br/>Response.Write("[&lt;a href=javascriptageNext()&gt;下一页&lt;/a&gt;] ") <br/>Response.Write("[&lt;a href=javascriptageLast()&gt;最后一页&lt;/a&gt;] ") <br/>end if<br/>end if<br/>end if<br/><br/>''创建下拉列表框,用于选择浏览页码<br/>Response.Write("第&lt;select size=1 name=CurrentPage onchange=PageCurrent()&gt;") <br/>For i=1 to rs.PageCount <br/>if rs.AbsolutePage=i then<br/>Response.Write("&lt;option selected&gt;"&amp;i&amp;"&lt;/option&gt;") ''当前页码<br/>else<br/>Response.Write("&lt;option&gt;"&amp;i&amp;"&lt;/option&gt;")<br/>end if <br/>Next <br/>Response.Write("&lt;/select&gt;页/共"&amp;rs.PageCount&amp;"页 共"&amp;rs.RecordCount&amp;"条记录&lt;/font&gt;&lt;p&gt;") <br/>Response.Write("&lt;/form&gt;")<br/><br/>''创建表格,用于显示<br/>Response.Write("&lt;table align=center cellspacing=1 cellpadding=1 border=1") <br/>Response.Write(" bordercolor=#99CCFF bordercolordark=#b0e0e6 bordercolorlight=#000066&gt;")<br/><br/>Response.Write("&lt;tr bgcolor=#ccccff bordercolor=#000066&gt;") <br/><br/>Set Columns=rs.Fields <br/><br/>''显示表头<br/>For i=0 to Columns.Count-1<br/>Response.Write("&lt;td align=center width=200 height=13&gt;")<br/>Response.Write("&lt;font size=2&gt;&lt;b&gt;"&amp;Columns(i).name&amp;"&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;") <br/>Next<br/>Response.Write("&lt;/tr&gt;")<br/>''显示内容<br/>For i=1 to rs.PageSize <br/>Response.Write("&lt;tr bgcolor=#99ccff bordercolor=#000066&gt;") <br/>For j=0 to Columns.Count-1 <br/>Response.Write("&lt;td&gt;&lt;font size=2&gt;"&amp;Columns(j)&amp;"&lt;/font&gt;&lt;/td&gt;") <br/>Next<br/>Response.Write("&lt;/tr&gt;")<br/><br/>rs.movenext <br/>if rs.EOF then exit for <br/>Next<br/><br/>Response.Write("&lt;/table&gt;") </p><p>END IF<br/>%&gt;<br/>&lt;/BODY&gt;<br/>&lt;/HTML&gt;<br/></p>

该用户从未签到

升级  30.8%

63
 楼主| 发表于 2006-2-24 09:24:38 | 只看该作者
<strong>新闻生成的例子<hr/></strong><p>====================================asptohtml1.asp<br/>&lt;html&gt;<br/>&lt;head&gt;<br/>&lt;title&gt;Untitled Document&lt;/title&gt;<br/>&lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312"&gt;<br/>&lt;/head&gt;</p><p>&lt;body bgcolor="#FFFFFF" text="#000000"&gt;<br/>&lt;div align="center"&gt;<br/>&lt;form name="form1" method="post" action="asptohtml2.asp"&gt;<br/>标题: <br/>&lt;input type="text" name="biaoti"&gt;<br/>&lt;br&gt;<br/>正文:<br/>&lt;textarea name="neirong"&gt;&lt;/textarea&gt;<br/>&lt;br&gt;<br/>&lt;input type="submit" name="Submit" value="Submit"&gt;<br/>&lt;/form&gt;<br/>&lt;/div&gt;<br/>&lt;/body&gt;<br/>&lt;/html&gt;<br/>=========================asptohtml2.asp<br/>&lt;%<br/>biaoti=request("biaoti")<br/>neirong=request("neirong")<br/>set fileobj=server.createobject("scripting.filesystemobject")<br/>filepath=server.mappath("./")&amp;"/"&amp;year(now)&amp;month(now)&amp;day(now)&amp;hour(now)&amp;minute(now)&amp;second(now)&amp;".html"<br/>response.write filepath<br/>set filewrite=fileobj.opentextfile(filepath,2,true)<br/>filewrite.write biaoti&amp;"&lt;br&gt;"<br/>filewrite.write neirong<br/>set fileobj=nothing<br/>%&gt;</p><p><br/>这样呢会在你的当前目录下生成一个根据日期及时分钟为文件名的.html文件,这样你需要做得就是把这个文件名,及文件的标题保存到一个表里,然后再输入这个表就可以了<br/>如:表中的字段有id,biaoti,timee(分别为,文件的id编号,带连接的文件名,生成时间)<br/>当然,你还可以再加上你需的字段,我这里只是举一个例子<br/>在html文件生成了后,你需要向这个表中的biaoti填加一条记录(如:&lt;a href=文件名&gt;提交后的文件名&lt;/a&gt;)</p><p>最后你只要输出这个表的所有内容就行了</p>

该用户从未签到

升级  30.8%

64
 楼主| 发表于 2006-2-24 09:24:54 | 只看该作者
<p><strong>利用XMLHTTP 从其他页面获取数据</strong></p><hr/><p>我们在编写ASP代码的时候,大家都知道可以通过post或者get获得form表单的数据,那么我们如何直接获得其他页面上的数据呢?这就要借助xmlhttp协议了。xmlhttp是xmldom技术的一部分。</p><p>下面的代码就是一个很简单的例子,我们利用xmlhttp技术,把http://www.xxxx.com/站点首页的代码以xml的形式完全获取,并且在页面中输出。</p><p>&lt;%<br/>Dim objXMLHTTP, xml<br/>Set xml = Server.CreateObject("Microsoft.XMLHTTP")<br/><br/>xml.Open "GET", "http://www.codetoad.com/", False<br/>' Pull the data from the web page<br/>xml.Send</p><p>Response.write "Here's the html we now have in our xml object"<br/>Response.write "&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;"<br/>Response.Write "&lt;xmp&gt;"<br/>Response.Write xml.responseText<br/>Response.Write "&lt;/xmp&gt;"<br/>Response.write "&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;"<br/>Response.write " Now here's how the page looks:&lt;BR&gt;&lt;BR&gt;"<br/>Response.Write xml.responseText</p><p>Set xml = Nothing<br/>%&gt;</p><p><br/>下面是另一个实例</p><p>&lt;%<br/>dim objHTTP , objXML , objXSL<br/>set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")<br/>objHTTP.open "GET", "http://p.moreover.com/cgi-local/page?c=Pop%20music%20reviews&amp;o=xml", false<br/>objHTTP.send<br/>set objXML = objHTTP.responseXML<br/>set objXSL=Server.CreateObject("microsoft.xmldom")<br/>objXSL.async=false</p><p>objXSL.load(Server.MapPath("style.xsl"))</p><p>if (objXSL.parseError.errorCode = 0) then<br/>Response.Write(objXML.transformnode(objXSL))<br/>else<br/>Response.Write "Error: " &amp; objXSL.parseError.reason &amp; " URL:" &amp; objXSL.url<br/>end if</p><p>Set objHTTP = Nothing<br/>Set objXML = Nothing<br/>Set objXSL = Nothing<br/>%&gt;</p><p>style.xsl:<br/>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"&gt;<br/>&lt;xsl:template match="/"&gt;</p><p>&lt;html&gt;<br/>&lt;head&gt;<br/>&lt;TITLE&gt;moreover...&lt;/TITLE&gt;<br/>&lt;/head&gt;<br/>&lt;body BGCOLOR="ffffff"&gt;</p><p></p><p><br/>&lt;DIV ALIGN="center"&gt;<br/>&lt;TABLE BGCOLOR="ffffff" BORDER="0" CELLPADDING="4" CELLSPACING="0" WIDTH="100%"&gt;</p><p>&lt;xsl:for-each select="moreovernews/article"&gt;<br/><br/>&lt;TR VALIGN="middle"&gt;<br/>&lt;TD ALIGN="left" BGCOLOR="ffffff"&gt;<br/><br/><br/>&lt;xsl:attribute name="HREF"&gt;<br/>&lt;xsl:value-of select="url"/&gt;<br/>&lt;/xsl:attribute&gt;<br/>&lt;xsl:attribute name="TARGET"&gt;<br/>_blank<br/>&lt;/xsl:attribute&gt;<br/><br/>&lt;xsl:value-of select="headline_text"/&gt;<br/><br/><br/><br/><br/><br/>&lt;xsl:attribute name="HREF"&gt;<br/>&lt;xsl:value-of select="document_url"/&gt;<br/>&lt;/xsl:attribute&gt;<br/>&lt;xsl:attribute name="TARGET"&gt;<br/>_blank<br/>&lt;/xsl:attribute&gt;<br/><br/>&lt;xsl:value-of select="source"/&gt;<br/><br/><br/><br/>&lt;xsl:attribute name="HREF"&gt;<br/>&lt;xsl:value-of select="access_registration"/&gt;<br/>&lt;/xsl:attribute&gt;<br/>&lt;xsl:attribute name="TARGET"&gt;<br/>_blank<br/>&lt;/xsl:attribute&gt;<br/><br/>&lt;xsl:value-of select="access_status"/&gt;<br/><br/><br/><br/>&lt;xsl:value-of select="harvest_time"/&gt; GMT<br/><br/>&lt;/TD&gt;<br/>&lt;/TR&gt;<br/><br/>&lt;/xsl:for-each&gt;</p><p><br/>&lt;/TABLE&gt;<br/>&lt;/DIV&gt;<br/>&lt;/body&gt;<br/>&lt;/html&gt;<br/>&lt;/xsl:template&gt;<br/>&lt;/xsl:stylesheet&gt;<br/></p>

该用户从未签到

升级  30.8%

65
 楼主| 发表于 2006-2-24 09:25:10 | 只看该作者
<p><strong>防止从外部提交数据的方法</strong></p><hr/><p>第一种做法,屏蔽特殊字符和关键字</p><p>fqys=request.servervariables("query_string") </p><p>dim nothis(18) </p><p>nothis(0)="net user" </p><p>nothis(1)="xp_cmdshell" </p><p>nothis(2)="/add" </p><p>nothis(3)="exec%20master.dbo.xp_cmdshell" </p><p>nothis(4)="net localgroup administrators" </p><p>nothis(5)="select" </p><p>nothis(6)="count" </p><p>nothis(7)="asc" </p><p>nothis(8)="char" </p><p>nothis(9)="mid" </p><p>nothis(10)="'" </p><p>nothis(11)=":" </p><p>nothis(12)="""" </p><p>nothis(13)="insert" </p><p>nothis(14)="delete" </p><p>nothis(15)="drop" </p><p>nothis(16)="truncate" </p><p>nothis(17)="from" </p><p>nothis(18)="%" </p><p>errc=false </p><p>for i= 0 to ubound(nothis) </p><p>if instr(FQYs,nothis(i))&lt;&gt;0 then </p><p>errc=true </p><p>end if </p><p>next </p><p>if errc then </p><p>response.write "&lt;script language=""javascript""&gt;" </p><p>response.write "parent.alert('很抱歉!你正在试图攻击本服务器或者想取得本服务器最高管理权!将直接转向首页..');" </p><p>response.write "self.location.href='default.asp';" </p><p>response.write "&lt;/script&gt;" </p><p>response.end </p><p>end if </p><hr/><p>第二种可以防止客户从本地提交到网站上</p><p>&lt;% </p><p>server_v1=Cstr(Request.ServerVariables("HTTP_REFERER")) </p><p>server_v2=Cstr(Request.ServerVariables("SERVER_NAME")) </p><p>if mid(server_v1,8,len(server_v2))&lt;&gt;server_v2 then </p><p>response.write "&lt;br&gt;&lt;br&gt;&lt;center&gt;&lt;table border=1 cellpadding=20 bordercolor=black bgcolor=#EEEEEE width=450&gt;" </p><p>response.write "&lt;tr&gt;&lt;td style=font:9pt Verdana&gt;" </p><p>response.write "你提交的路径有误,禁止从站点外部提交数据请不要乱该参数!" </p><p>response.write "&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/center&gt;" </p><p>response.end </p><p>end if </p><p>%&gt; </p><hr/><p>第三。这样可以防止在输入框上打上or 1=1 的字样 </p><p>If Instr(request("username"),"=")&gt;0 or </p><p>Instr(request("username"),"%")&gt;0 or </p><p>Instr(request("username"),chr(32))&gt;0 or </p><p>Instr(request("username"),"?")&gt;0 or </p><p>Instr(request("username"),"&amp;")&gt;0 or </p><p>Instr(request("username"),";")&gt;0 or </p><p>Instr(request("username"),",")&gt;0 or </p><p>Instr(request("username"),"'")&gt;0 or </p><p>Instr(request("username"),"?")&gt;0 or </p><p>Instr(request("username"),chr(34))&gt;0 or </p><p>Instr(request("username"),chr(9))&gt;0 or </p><p>Instr(request("username"),"?")&gt;0 or </p><p>Instr(request("username"),"$")&gt;0 or </p><p>Instr(request("username"),"&gt;")&gt;0 or </p><p>Instr(request("username"),"&lt;")&gt;0 or </p><p>Instr(request("username"),"""")&gt;0 then </p>

该用户从未签到

升级  30.8%

66
 楼主| 发表于 2006-2-24 09:25:27 | 只看该作者
<p><strong>ASP用JMail、CDO发送邮件 </strong></p><hr/><p>  前一段时间有发过一个简单的JMAIL邮件发邮件的代码,今天就把这个代码做一个具体的注解,并增加了另外两个格式的代码,并举几个简单的例子:<br/>  首先是jmail.smtpmail的核心代码:</p><p>&lt;%<br/>Set jmail = Server.CreateObject("JMAIL.SMTPMail") '创建一个JMAIL对象<br/>jmail.silent = true 'JMAIL不会抛出例外错误,返回的值为FALSE跟TRUE<br/>jmail.logging = true '启用使用日志<br/>jmail.Charset = "GB2312" '邮件文字的代码为简体中文<br/>jmail.ContentType = "text/html" '邮件的格式为HTML的<br/>jmail.ServerAddress = "Server Address" '发送邮件的服务器<br/>jmail.AddRecipient Email '邮件的收件人<br/>jmail.SenderName = "SenderName" '邮件发送者的姓名<br/>jmail.Sender = "Email Address" '邮件发送者的邮件地址<br/>jmail.Priority = 1 '邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值<br/>jmail.Subject = "Mail Subject" '邮件的标题<br/>jmail.Body = "Mail Body" '邮件的内容<br/>jmail.AddRecipientBCC Email '密件收件人的地址<br/>jmail.AddRecipientCC Email '邮件抄送者的地址<br/>jmail.Execute() '执行邮件发送<br/>jmail.Close '关闭邮件对象<br/>%&gt;</p><p>  w3 Jmail4.3组件重新设计了其内部结构——使用Message对象代替原来的单一对象Jmail.smtpmail发送邮件,有些方法需要身份验证的(如163、yahoo等),可以用下面的方法解决:<br/>&lt;%<br/>Set jmail = Server.CreateObject("JMAIL.Message") '建立发送邮件的对象<br/>jmail.silent = true '屏蔽例外错误,返回FALSE跟TRUE两值j<br/>mail.logging = true '启用邮件日志<br/>jmail.Charset = "GB2312" '邮件的文字编码为国标<br/>jmail.ContentType = "text/html" '邮件的格式为HTML格式<br/>jmail.AddRecipient Email '邮件收件人的地址<br/>jmail.From = "Email From for Sender" '发件人的E-MAIL地址<br/>jmail.MailServerUserName = "UserName of Email" '登录邮件服务器所需的用户名<br/>jmail.MailServerPassword = "assword of Email" '登录邮件服务器所需的密码<br/>jmail.Subject = "Mail Subject" '邮件的标题 <br/>jmail.Body = "Mail Body" '邮件的内容<br/>jmail.Prority = 1 '邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值<br/>jmail.Send("Server Address") '执行邮件发送(通过邮件服务器地址)<br/>jmail.Close() '关闭对象<br/>%&gt;</p><p>  再讲一下微软自带的CDONTS组件的发信的方法: </p><p>&lt;%<br/>Set cdomail = Server.CreateObject("CDONTS.NewMail") '建立邮件对象<br/>cdomail.Subject = "Mail Subject" '邮件标题<br/>cdomail.From = "Sender's Mail" '发件人的地址<br/>cdomail.To = "Email will from" '收件人的地址<br/>cdomail.Body = "Mail Body" '邮件的内容<br/>cdomail.Send '执行发送<br/>%&gt;</p><p>  这种方法发送邮件是最简单的,同时也带来一定的问题,就是很少有服务器会开这项服务!</p><p><br/>  我们写程序,一般情况下都是说要代码模块化,这样方便维护,同时也方便移植。因此,我在这里将这个发邮件的写成一个子程,在调用的时候可以直接调用(当然,如果你高兴写成函数的话也是可以的,这个主要是看个人兴趣):</p><p>&lt;%<br/>'参数说明<br/>'Subject : 邮件标题<br/>'MailAddress : 发件服务器的地址,如smtp.163.com<br/>'Email : 收件人邮件地址<br/>'Sender : 发件人姓名<br/>'Content : 邮件内容<br/>'Fromer : 发件人的邮件地址</p><p>Sub SendAction(subject, mailaddress, email, sender, content, fromer) <br/>Set jmail = Server.CreateObject("JMAIL.SMTPMail") '创建一个JMAIL对象<br/>jmail.silent = true 'JMAIL不会抛出例外错误,返回的值为FALSE跟TRUE<br/>jmail.logging = true '启用使用日志<br/>jmail.Charset = "GB2312" '邮件文字的代码为简体中文<br/>jmail.ContentType = "text/html" '邮件的格式为HTML的<br/>jmail.ServerAddress = mailaddress '发送邮件的服务器<br/>jmail.AddRecipient Email '邮件的收件人<br/>jmail.SenderName = sender '邮件发送者的姓名<br/>jmail.Sender = fromer '邮件发送者的邮件地址<br/>jmail.Priority = 1 '邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值<br/>jmail.Subject = subject '邮件的标题<br/>jmail.Body = content '邮件的内容<br/>'由于没有用到密抄跟抄送,这里屏蔽掉这两句,如果您有需要的话,可以在这里恢复<br/>'jmail.AddRecipientBCC Email '密件收件人的地址<br/>'jmail.AddRecipientCC Email '邮件抄送者的地址<br/>jmail.Execute() '执行邮件发送<br/>jmail.Close '关闭邮件对象<br/>End Sub<br/><br/>'调用此Sub的例子<br/>Dim strSubject,strEmail,strMailAdress,strSender,strContent,strFromer<br/>strSubject = "这是一封用JMAIL发送的测试邮件"<br/>strContent = "JMail组件发送测试成功!"<br/>strEmail = "runbing@eyou.com"<br/>strFromer = "runbing@eyou.com"<br/>strMailAddress = "mail.ubbcn.com"</p>

该用户从未签到

升级  30.8%

67
 楼主| 发表于 2006-2-24 09:25:43 | 只看该作者
<p><strong>IP限制函数</strong></p><hr/><p>大家如果还有好的建议算法,就联系我!!:)</p><p>“******************************<br/>“Function CheckIp(cInput_Ip,cBound_Ip)<br/>“Created by qqdao, qqdao@263.net 2001/11/28<br/>“说明:首先需要根据;号循环,然后判断是否含有"-",如果有则进行拆分处理,最后判断是否在范围内<br/>“参数: cInput_Ip,代检查的ip<br/>“ cBound_Ip,给定的范围格式为,单个ip,和范围ip,范围ip最后使用”-“分割,如果是“*”则必须放到最后一位<br/>“ 每个范围后添加":ALLOW"表示允许登陆,添加":REFUSE"表示拒绝登陆。多个范围用”;“隔开<br/>“ 例如192.168.1*.*:ALLOW;192.168.1.1:ALLOW;192.168.1.1-10:REFUSE"<br/>“返回值: true/false<br/>“更新:2001/12/05 支持ALLOW,REFUSE支持’*‘,不想对?支持,因为和*差不多<br/>“******************************<br/>function CheckIp(cInput_Ip,cBound_Ip)<br/>dim cSingle_Ip,cTemp_IP,cStart_IP,cEnd_Ip<br/>CheckIp = false<br/>cSingle_Ip=split(cBound_Ip,";")</p><p>for i=0 to ubound(cSingle_Ip)<br/>if Instr(cSingle_Ip(i),"REFUSE") &lt;&gt; 0 then “就是拒绝了<br/>cTemp_IP = left(cSingle_Ip(i),instr(cSingle_Ip(i),":")-1)</p><p>if Instr(cTemp_IP,"*") &lt;&gt; 0 then “是宽范围<br/>cStart_IP = left(cTemp_IP,instr(cTemp_IP,"*")-1)<br/>if left(cInput_Ip,len(cStart_IP))=cStart_IP then<br/>CheckIp = false<br/>exit function<br/>end if<br/>end if</p><p>if Instr(cTemp_IP,"-") = 0 then<br/>cStart_IP = cTemp_IP<br/>cEnd_Ip = cTemp_IP<br/>else<br/>cStart_IP = left(cTemp_IP,instr(cTemp_IP,"-")-1)<br/>cEnd_Ip = left(cStart_IP,InStrRev(cStart_IP,".")-1)+"."+mid(cTemp_IP,instr(cTemp_IP,"-")+1)<br/>end if</p><p>if Ip2Str(cInput_Ip)&gt;=Ip2Str(cStart_IP) and Ip2Str(cInput_Ip)&lt;=Ip2Str(cEnd_Ip) then<br/>CheckIp = false<br/>exit function<br/>end if</p><p>elseif Instr(cSingle_Ip(i),"ALLOW") &lt;&gt; 0 then “允许</p><p>cTemp_IP = left(cSingle_Ip(i),instr(cSingle_Ip(i),":")-1)</p><p>if Instr(cTemp_IP,"*") &lt;&gt; 0 then “是宽范围<br/>cStart_IP = left(cTemp_IP,instr(cTemp_IP,"*")-1)<br/>if left(cInput_Ip,len(cStart_IP))=cStart_IP then<br/>CheckIp = true<br/>end if<br/>end if</p><p>if Instr(cTemp_IP,"-") = 0 then<br/>cStart_IP = cTemp_IP<br/>cEnd_Ip = cTemp_IP<br/>else<br/>cStart_IP = left(cTemp_IP,instr(cTemp_IP,"-")-1)<br/>cEnd_Ip = left(cStart_IP,InStrRev(cStart_IP,".")-1)+"."+mid(cTemp_IP,instr(cTemp_IP,"-")+1)<br/>end if</p><p>if Ip2Str(cInput_Ip)&gt;=Ip2Str(cStart_IP) and Ip2Str(cInput_Ip)&lt;=Ip2Str(cEnd_Ip) then<br/>CheckIp =true<br/>else<br/>CheckIp =false<br/>end if<br/>end if<br/>next</p><p>end function</p><p><br/>“******************************<br/>“Function Ip2Str(cIp)<br/>“Created by qqdao, qqdao@263.net 2001/11/28<br/>“参考动网ip算法<br/>“参数:cIp ip地址<br/>“返回值: 转换后数值<br/>“******************************<br/>function Ip2Str(cIp)<br/>Dim str1,str2,str3,str4<br/>Dim cIp_Temp<br/>if cIp="127.0.0.1" then cIp="192.168.0.1"<br/>str1=left(cIp,instr(cIp,".")-1)<br/>cIp_Temp=mid(cIp,instr(cIp,".")+1)<br/>str2=left(cIp_Temp,instr(cIp_Temp,".")-1)<br/>cIp_Temp=mid(cIp_Temp,instr(cIp_Temp,".")+1)<br/>str3=left(cIp_Temp,instr(cIp_Temp,".")-1)<br/>str4=mid(cIp_Temp,instr(cIp_Temp,".")+1)</p><p>if isNumeric(str1)=0 or isNumeric(str2)=0 or isNumeric(str3)=0 or isNumeric(str4)=0 then</p><p>else<br/>Ip2Str=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1<br/>end if</p><p>end function <br/></p>

该用户从未签到

升级  30.8%

68
 楼主| 发表于 2006-2-24 09:25:59 | 只看该作者
<p><strong>IP地址分段计算</strong></p><hr/><p>&lt;script language="JScript" Runat="Server"&gt;<br/>function IPDeCode(EIP){<br/>var Ip1,Ip2,Ip3,Ip4;<br/>Ip1 = moveByteR(EIP &amp; 0xff000000,3);<br/>Ip2 = moveByteR(EIP &amp; 0x00ff0000,2);<br/>Ip3 = moveByteR(EIP &amp; 0x0000ff00,1);<br/>Ip4 = EIP &amp; 0x000000ff;<br/>return Ip1 + "." + Ip2 + "." + Ip3 + "." + Ip4;<br/>}</p><p><br/>function moveByteL(num,bytenum){<br/>return num &lt;&lt;= (bytenum*8)<br/>}</p><p>function moveByteR(num,bytenum){<br/>return num &gt;&gt;&gt;= (bytenum*8)<br/>}</p><p>&lt;/script&gt;</p><p><br/>在vbs中没有位操作,这样在一个页面中用到了js和vbs,并不好,如果用vbs也可以,不过罗嗦了一些,而且有一点注意,如果在vbs中split("202.102.29.6","."),会得到202,102,29三个数,得不到最后一个6,所以需要将ip换成split("202.102.29.6" &amp; ".",".")<br/>我用vbs做的,由于没有位操作,所以做得比较麻烦<br/>&lt;%<br/>function ip2int(ipstr)<br/>dim iptemp,max<br/>iptemp = split(ipstr&amp;".",".")<br/>max = ubound(iptemp)<br/>if max &lt;&gt; 4 then<br/>exit function<br/>end if</p><p>dim a,b,i<br/>a = "&amp;H"<br/>for i = 0 to 3<br/>b = Hex(iptemp(i))<br/>if len(b) = 1 then<br/>b = "0"&amp;b<br/>end if<br/>a = a&amp;b<br/>next<br/>ip2int = CLng(a)<br/>end function</p><p>function int2ip(ip)<br/>dim iptemp,a,ipstr,i,length<br/>iptemp = Hex(ip)<br/>length = 8 - len(iptemp)<br/>for i = 1 to length<br/>iptemp = "0" &amp; iptemp<br/>next<br/>a = left(iptemp,2)<br/>a = "&amp;H" &amp; a<br/>i = CInt(a)<br/>a = CStr(i)<br/>ipstr = a &amp; "."<br/>a = mid(iptemp,3,2)<br/>a = "&amp;H" &amp; a<br/>i = CInt(a)<br/>a = CStr(i)<br/>ipstr = ipstr &amp; a &amp; "."<br/>a = mid(iptemp,5,2)<br/>a = "&amp;H" &amp; a<br/>i = CInt(a)<br/>a = CStr(i)<br/>ipstr = ipstr &amp; a &amp; "."<br/>a = right(iptemp,2)<br/>a = "&amp;H" &amp; a<br/>i = CInt(a)<br/>a = CStr(i)<br/>ipstr = ipstr &amp; a<br/>int2ip = ipstr<br/>end function</p><p>dim testIP,testInt<br/>testIP="202.102.29.6"<br/>testInt = ip2int(testIP)<br/>response.write testIP &amp; " will be encoded to &lt;font color=red&gt;" &amp; testInt &amp; "&lt;/font&gt;&lt;br&gt;"<br/>response.write testIP &amp; " will be dencoded to &lt;font color=red&gt;" &amp; int2ip(testInt) &amp; "&lt;/font&gt;&lt;br&gt;"<br/>%&gt;</p>

该用户从未签到

升级  30.8%

69
 楼主| 发表于 2006-2-24 09:26:14 | 只看该作者
<p><strong>身份证验证代码函数</strong></p><hr/><p>Function CheckCardId(e)</p><p>arrVerifyCode = Split("1,0,x,9,8,7,6,5,4,3,2", ",")</p><p>Wi = Split("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2", ",")</p><p>Checker = Split("1,9,8,7,6,5,4,3,2,1,1", ",")<br/><br/>If Len(e) &lt; 15 Or Len(e) = 16 Or Len(e) = 17 Or Len(e) &gt; 18 Then<br/>CheckCardId= "身份证号共有 15 码或18位"<br/>CheckCardId = False<br/>Exit Function<br/>End If<br/><br/>Dim Ai<br/>If Len(e) = 18 Then<br/>Ai = Mid(e, 1, 17)<br/>ElseIf Len(e) = 15 Then<br/>Ai = e<br/>Ai = Left(Ai, 6) &amp; "19" &amp; Mid(Ai, 7, 9)<br/>End If<br/>If Not IsNumeric(Ai) Then<br/>CheckCardId= "身份证除最后一位外,必须为数字!"<br/><br/>Exit Function<br/>End If<br/>Dim strYear, strMonth, strDay<br/>strYear = CInt(Mid(Ai, 7, 4))<br/>strMonth = CInt(Mid(Ai, 11, 2))<br/>strDay = CInt(Mid(Ai, 13, 2))</p><p>BirthDay = Trim(strYear) + "-" + Trim(strMonth) + "-" + Trim(strDay)<br/>If IsDate(BirthDay) Then<br/>If DateDiff("yyyy",Now,BirthDay)&lt;-140 or cdate(BirthDay)&gt;date() Then<br/><br/>CheckCardId= "身份证输入错误!"</p><p>Exit Function<br/>End If<br/>If strMonth &gt; 12 Or strDay &gt; 31 Then<br/>CheckCardId= "身份证输入错误!"</p><p>Exit Function<br/>End If<br/>Else<br/>CheckCardId= "身份证输入错误!"</p><p>Exit Function<br/>End If<br/>Dim i, TotalmulAiWi<br/>For i = 0 To 16<br/>TotalmulAiWi = TotalmulAiWi + CInt(Mid(Ai, i + 1, 1)) * Wi(i)<br/>Next<br/>Dim modValue<br/>modValue = TotalmulAiWi Mod 11<br/>Dim strVerifyCode<br/>strVerifyCode = arrVerifyCode(modValue)<br/>Ai = Ai &amp; strVerifyCode<br/>CheckCardId = Ai<br/><br/>If Len(e) = 18 And e &lt;&gt; Ai Then<br/>CheckCardId= "身份证号码输入错误!"<br/>Exit Function<br/>End If<br/>End Function</p><p>response.write CheckCardId("528337194801020025") '''''''''这个不知是谁的身份证,我一试就出来了~~~~~~~~~哈哈</p><p></p><p>'''''这个如果返回的是输入的身份证,则表明正确,否则会提示出错...</p>

该用户从未签到

升级  30.8%

70
 楼主| 发表于 2006-2-24 09:26:28 | 只看该作者
<p><strong>Cookie读写例子</strong></p><hr/><p>writecookie.asp <br/><br/>&lt;%@ Language=VBScript  <br/>%&gt; <br/>&lt;%Response.Buffer=true%&gt; <br/>&lt;HTML&gt; <br/>&lt;HEAD&gt; <br/>&lt;META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"&gt; <br/>&lt;TITLE&gt;写Cookie的示例&lt;/TITLE&gt; <br/>&lt;/HEAD&gt; <br/>&lt;BODY&gt; <br/><br/>&lt;% <br/>Response.Write "写Cookie:<br/>" <br/>Response.Cookies("Cookie1")("key1") = "KeyValue1" <br/>Response.Cookies("Cookie1")("key1") = "KeyValue2" <br/>Response.Cookies("Cookie1").Expires = "July 31, 1999" <br/><br/>Response.Cookies("Cookie2")("key2") = "KeyValue1" <br/>Response.Cookies("Cookie2")("key2") = "KeyValue2" <br/>Response.Cookies("Cookie2").Expires = "July 31, 1999" <br/>'Response.Cookies("Cookie2").Path = "/testasp/" <br/>'这个在使用的时候要注意 <br/>'是指定在那个目录的文件才可以读取这个cookie的内容。 <br/>'在本例子中。只有在testasp这目录下的文件才可以读取 <br/>'Cookie2的内容。 <br/>%&gt; <br/><br/>&lt;/BODY&gt; <br/>&lt;/HTML&gt; <br/><br/>------------------------------------------------------- <br/>readwrite.asp <br/><br/>&lt;%@ Language=VBScript %&gt; <br/>&lt;HTML&gt; <br/>&lt;HEAD&gt; <br/>&lt;META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"&gt; <br/>&lt;TITLE&gt;读Cookie的示例&lt;/TITLE&gt; <br/>&lt;/HEAD&gt; <br/>&lt;BODY&gt; <br/><br/>&lt;%Response.Write "读取Cookie:<br/>" <br/><br/>dim cookie,key <br/>  <br/> for each cookie in Request.Cookies <br/>if Request.Cookies(cookie).haskeys then <br/>Response.Write "<br/>Cookie 名字:"&amp;cookie&amp;"&lt;BR&gt;--------------&lt;BR&gt;" <br/>for each key in Request.Cookies(cookie) <br/><br/>Response.Write "Key 名字:"&amp;key&amp;",值:"&amp;Request.Cookies(cookie)(ke <br/>y)&amp;"&lt;BR&gt;" <br/>next <br/>else <br/>Response.Write "Cookie 名字:"&amp;Request.Cookies(cookie)&amp;"&lt;BR&gt;" <br/>end if <br/>  <br/> next <br/>  <br/>%&gt; <br/>&lt;/BODY&gt; <br/>&lt;/HTML&gt; <br/></p>
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

小黑屋|手机版|Archiver|信息系统项目管理师_软考交流平台. ( 鄂ICP备11002878号-1  公安备案号:42011102001150

GMT+8, 2025-7-5 22:34

Software by Discuz! X3.2

© 2001-2013 SKIN BY DSVUE

快速回复 返回顶部 返回列表