我的人生路 |
|
|||
日歷
統計
導航常用鏈接留言簿(5)隨筆分類隨筆檔案文章分類文章檔案相冊顏色
搜索最新評論
閱讀排行榜評論排行榜 |
在大型的ASP項目中,很多的頁面都涉及到翻頁功能。如果每個頁面都寫一個翻頁的程序的話,這樣的工作即降低了工作效率,也不利于工程的模塊化,不能使代碼重用。因此,把翻頁這樣的功能模塊化是很有必要的。
設計方法: 1、調用該模塊時,只需要傳遞記錄集和每頁顯示的記錄的條數; 2、可以點擊鏈接進行翻頁,也可以直接輸入頁碼,回車后翻頁; 3、不要考慮文件名,程序的每次翻頁都能在當前頁面。 想清楚了上面3個問題,我們的公共翻頁模塊就可以動手了。 <% '+++++++++++++++++++++++++++++++++++++ '◆模塊名稱: 公共翻頁模塊 '◆文 件 名: TurnPage.asp '◆傳入參數: Rs_tmp (記錄集), PageSize (每頁顯示的記錄條數) '◆輸 出: 記錄集翻頁顯示功能 '+++++++++++++++++++++++++++++++++++++ ' Sub TurnPage(ByRef Rs_tmp,PageSize) 'Rs_tmp 記錄集 ; PageSize 每頁顯示的記錄條數; Dim TotalPage '總頁數 Dim PageNo '當前顯示的是第幾頁 Dim RecordCount '總記錄條數 Rs_tmp.PageSize = PageSize RecordCount = Rs_tmp.RecordCount TotalPage = INT(RecordCount / PageSize * -1)*-1 PageNo = Request.QueryString ("PageNo") '直接輸入頁數跳轉; If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo") '如果沒有選擇第幾頁,則默認顯示第一頁; If PageNo = "" then PageNo = 1 If RecordCount <> 0 then Rs_tmp.AbsolutePage = PageNo End If '獲取當前文件名,使得每次翻頁都在當前頁面進行; Dim fileName,postion fileName = Request.ServerVariables("script_name") postion = InstrRev(fileName,"/")+1 '取得當前的文件名稱,使翻頁的鏈接指向當前文件; fileName = Mid(fileName,postion) %> <table border=0 width='100%'> <tr> <td align=left> 總頁數:<font color=#ff3333><%=TotalPage%></font>頁 當前第<font color=#ff3333><%=PageNo%></font>頁</td> <td align="right"> <%If RecordCount = 0 or TotalPage = 1 Then Response.Write "首頁|前頁|后頁|末頁" Else%> <a href="<%=fileName%>?PageNo=1">首頁|</a> <%If PageNo - 1 = 0 Then Response.Write "前頁|" Else%> <a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前頁|</a> <%End If If PageNo+1 > TotalPage Then Response.Write "后頁|" Else%> <a href="<%=fileName%>?PageNo=<%=PageNo+1%>">后頁|</a> <%End If%> <a href="<%=fileName%>?PageNo=<%=TotalPage%>">末頁</a> <%End If%></td> <td width=95>轉到第 <%If TotalPage = 1 Then%> <input type=text name=PageNo size=3 readonly disabled style="background:#d3d3d3"> <%Else%> <input type=text name=PageNo size=3 value="" title=請輸入頁號,然后回車> <%End If%>頁 </td> </tr> </table> <%End Sub%> 當然,大家可以把翻頁的鏈接做成圖片按鈕,這樣的話也面就更加美觀了。 調用方法: 1、在程序開始或要使用翻頁的地方包含翻頁模塊文件; 2、定義變量:RowCount,每頁顯示的記錄條數 3、調用翻頁過程:Call TurnPage(記錄集,RowCount) 4、在Do While 循環輸出記錄集的條件中加上" RowCount > 0 " 條件 5、在循環結束 "Loop前" 加上: RowCount = RowCount - 1 '----------------------------------------------------- 調用范例: 文件名:News.asp <% Dim Conn,Rs_News Set Conn = server.CreateObject("ADODB.CONNECTION") Conn.Open "cpm","cpm","cpm" Dim Sql Sql = "Select * from News" Set Rs_News = Server.CreateObject("ADODB.RECORDSET") Rs_News.Open Sql,Conn,1,3 '獲取的記錄集 '公共翻頁模塊開始%> <!--#include file=../Public/TurnPage.asp--> <% Dim RowCount RowCount = 10 '每頁顯示的記錄條數 Call TurnPage(Rs_News,RowCount) '公共翻頁模塊結束%> <table width=100%> <tr> <td>新聞編號</td> <td>新聞標題</td> <td>發布日期</td> <tr> <% If Not Rs_News.eof Do while Not Rs_News.eof and RowCount>0 %> <tr> <td><%=Rs_News("ID")%></td> <td><%=Rs_News("Name")%></td> <td><%=Rs_News("Date")%></td> <tr> <% RowCount = RowCount - 1 Rs_News.MoveNext Loop End If %> 修正: <% If Not Rs_News.eof then Do while Not Rs_News.eof and RowCount>0 %> 而那個公共模塊缺<form>,改后: <% Sub TurnPage(ByRef Rs_tmp,PageSize) 'Rs_tmp 記錄集 ; PageSize 每頁顯示的記錄條數; Dim TotalPage '總頁數 Dim PageNo '當前顯示的是第幾頁 Dim RecordCount '總記錄條數 Rs_tmp.PageSize = PageSize RecordCount = Rs_tmp.RecordCount TotalPage = INT(RecordCount / PageSize * -1)*-1 PageNo = Request.QueryString ("PageNo") '直接輸入頁數跳轉; If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo") '如果沒有選擇第幾頁,則默認顯示第一頁; If PageNo = "" then PageNo = 1 If RecordCount <> 0 then Rs_tmp.AbsolutePage = PageNo End If '獲取當前文件名,使得每次翻頁都在當前頁面進行; Dim fileName,postion fileName = Request.ServerVariables("script_name") postion = InstrRev(fileName,"/")+1 fileName = Mid(fileName,postion) %> <table border=0 width='100%'> <tr> <td width="258" align=left> 總頁數:<font color=#ff3333><%=TotalPage%></font>頁 當前第<font color=#ff3333><%=PageNo%></font>頁 總共<%=RecordCount%>條 </td> <td width="308" align="right"> <div align="center"> <%If RecordCount = 0 or TotalPage = 1 Then Response.Write "首頁|前頁|后頁|末頁" Else%> <a href="<%=fileName%>?PageNo=1">首頁|</a> <%If PageNo - 1 = 0 Then Response.Write "前頁|" Else%> <a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前頁|</a> <%End If If PageNo+1 > TotalPage Then Response.Write "后頁|" Else%> <a href="<%=fileName%>?PageNo=<%=PageNo+1%>">后頁|</a> <%End If%> <a href="<%=fileName%>?PageNo=<%=TotalPage%>">末頁</a> <%End If%> </div></td> <td width=189><form name="form1" method="post" action=""> 轉到第 <% If TotalPage = 1 Then%> <input type=text name=PageNo size=3 readonly disabled style="background:#d3d3d3"> <input type="submit" name="Submit" value="Go" disabled style="background:#d3d3d3"> <%Else%> <input type=text name=PageNo size=3 > <input type="submit" name="Submit" value="Go"> <%End If%> </form> 頁 </td> </tr> </table> <%End Sub%> 我們在管理網站文件時,可以把擴展名一樣的文件放在同一個目錄下,起一個比較特別名字,例如放pdf文件目錄為the_pdf_file_s,把下面代碼另存為down.asp,他的網上路徑為http://www.xx.com/down.asp,我們就可以用http://www.xx.com/down.asp?FileName=51windows.pdf來下載這個文件了,而且下載者無法看到這個文件實際下載路徑的!在down.asp中我們還可以設置下載文件是否需要登陸,判斷下載的來源頁是否為外部網站,從而可以做到防止文件被盜鏈。 示例代碼: <% if Request.Cookies("Logined")="" then 會員注冊以后,有些會員可能會遇到忘記登錄密碼的問題,因而網站具備“找回密碼”功能不僅是必須的,而且是服務貼心的具體表現之一。在此,levitian寫了一個“找回密碼”的小教程,供初學動態網站設計的朋友們借鑒,希望對大家有所幫助。
在ASP中加密方法有對應的解密方法好象不多,現在根據前輩資料整理出在asp中加密與解密函數 rsa.asp Public PrivateKey Public Function Encode(ByVal pStrMessage) Private Function HexToNumber(ByRef pStrHex) End Class test.asp
ObjRSA.PrivateKey =LngKeyD dim last,first %> <SCRIPT language="javascript"> 用onunload事件打開上面的文件 quit.asp為保存數據的文件,上面的文件用來檢測窗口是關閉還是刷新 ie5兼容,以前使用 window.opener.closed來判斷,ie5不支持closed 屬性。 'pop3的連接用戶名,密碼,pop3地址 pop3.Connect "username", "password", "mail.mydomain.com" Response.Write( "你有" & pop3.count & " 封郵件。<br><br>" ) if pop3.count > 0 then Set msg = pop3.Messages.item(1) ReTo = "" ReCC = "" Set Recipients = msg.Recipients separator = ", " ' 現在得到所有的收件人,并且存儲 For i = 0 To Recipients.Count - 1 If i = Recipients.Count - 1 Then separator = "" End If Set re = Recipients.item(i) If re.ReType = 0 Then ReTo = ReTo & re.Name & " (<a href=""mailto:"& re.EMail &""">" & re.EMail & "</a>)" & separator else ReCC = ReTo & re.Name & " (<a href=""mailto:"& re.EMail &""">" & re.EMail & "</a>)" & separator End If Next '這個程序得到附件,并且保存到服務器的硬盤上。也可以返回附件的詳細連接 Function getAttachments() Set Attachments = msg.Attachments separator = ", " For i = 0 To Attachments.Count - 1 If i = Attachments.Count - 1 Then separator = "" End If Set at = Attachments(i) at.SaveToFile( "c:\EMail\attachments\" & at.Filename ) getAttachments = getAttachments & "<a href=""/EMail/attachments/" & at.Filename &""">" &_ at.FileName & "(" & at.Size & " bytes)" & "</a>" & separator Next End Function %> <html> <body> <TABLE> <tr> <td>郵件標題</td> <td><%= msg.Subject %></td> </tr> <tr> <td>發件人</td> <td><%= msg.FromName %></td> </tr> <tr> <td>收件人</td> <td><%= ReTO %></td> </tr> <tr> <td>抄送</td> <td><%= ReCC %></td> </tr> <tr> <td>附件</td> <td><%= getAttachments %></td> </tr> <tr> <td>內容</td> <td><pre><%= msg.Body %></pre></td> </tr> </TABLE> </body> </html> <% end if pop3.Disconnect %> <% server_v1=Cstr(Request.ServerVariables("HTTP_REFERER")) server_v2=Cstr(Request.ServerVariables("SERVER_NAME")) if mid(server_v1,8,len(server_v2))<>server_v2 then response.write "<br><br><center><table border=1 cellpadding=20 bordercolor=black bgcolor=#EEEEEE width=450>" response.write "<tr><td style='font:9pt Verdana'>" response.write "你提交的路徑有誤,禁止從站點外部提交數據請不要亂該參數!" response.write "</td></tr></table></center>" response.end end if %> 防止從外部提交數據的方法: ******************************* 第一種做法,屏蔽特殊字符和關鍵字 fqys=request.servervariables("query_string") dim nothis(18) nothis(0)="net user" nothis(1)="xp_cmdshell" nothis(2)="/add" nothis(3)="exec%20master.dbo.xp_cmdshell" nothis(4)="net localgroup administrators" nothis(5)="select" nothis(6)="count" nothis(7)="asc" nothis(8)="char" nothis(9)="mid" nothis(10)="'" nothis(11)=":" nothis(12)="""" nothis(13)="insert" nothis(14)="delete" nothis(15)="drop" nothis(16)="truncate" nothis(17)="from" nothis(18)="%" errc=false for i= 0 to ubound(nothis) if instr(FQYs,nothis(i))<>0 then errc=true end if next if errc then response.write "<script language=""javascript"">" response.write "parent.alert('很抱歉!你正在試圖攻擊本服務器或者想取得本服務器最高管理權!將直接轉向首頁..');" response.write "self.location.href='default.asp';" response.write "</script>" response.end end if 第二種可以防止客戶從本地提交到網站上 <% server_v1=Cstr(Request.ServerVariables("HTTP_REFERER")) server_v2=Cstr(Request.ServerVariables("SERVER_NAME")) if mid(server_v1,8,len(server_v2))<>server_v2 then response.write "<br><br><center><table border=1 cellpadding=20 bordercolor=black bgcolor=#EEEEEE width=450>" response.write "<tr><td style=font:9pt Verdana>" response.write "你提交的路徑有誤,禁止從站點外部提交數據請不要亂該參數!" response.write "</td></tr></table></center>" response.end end if %> 第三。這樣可以防止在輸入框上打上or 1=1 的字樣 If Instr(request("username"),"=")>0 or Instr(request("username"),"%")>0 or Instr(request("username"),chr(32))>0 or Instr(request("username"),"?")>0 or Instr(request("username"),"&")>0 or Instr(request("username"),";")>0 or Instr(request("username"),",")>0 or Instr(request("username"),"'")>0 or Instr(request("username"),"?")>0 or Instr(request("username"),chr(34))>0 or Instr(request("username"),chr(9))>0 or Instr(request("username"),"")>0 or Instr(request("username"),"$")>0 or Instr(request("username"),">")>0 or Instr(request("username"),"<")>0 or Instr(request("username"),"""")>0 then 程序RAR.EXE這個文件就可以了。然后就要上傳一個執行RAR.EXE的程序 CMD.EXE 這個是windows里的程序(不必我在多說了吧)。最后就開始執行這些程序了。看一下下面的代碼 <% dim ylj,ywj,Mlpath,Shell,rarcomm,RetCode,cmd,comm,fso Mlpath="E:\page\mian\" '存放RAR.EXE和CMD.EXE的路徑 ylj=Server.mappath("mian")&"\" '解壓文件后所放的路徑 ywj=Server.mappath("mian\apathy.rar") '要解壓的RAR文件 Set Shell = Server.CreateObject("WScript.Shell") rarcomm= "E:\page\mian\cmd.exe /c "&Mlpath&"rar.exe x -t -o+ -p- " cmd=rarcomm&ywj&" "&ylj RetCode = Shell.Run(cmd,1, True) %> 就是用Server.CreateObject("WScript.Shell")來執行CMD.EXE來運行RAR.EXE文件來解壓RAR文件的。 以前不知道是否有前輩們發表過這些文章,但那位兄弟有興趣的可以以用這種方法來實現諸多類似與這樣的程序,希望你們可以找到一些更好的方法。 1、必須有一個頂級域名,而且此域名必須做好泛解析并做好指向。 2、必須有一臺獨立的服務器。泛解析的域名指向該服務器。 3、在服務器上的IIS建一個空的主機頭名的web站點。 4、將默認的頁面設置為你的二機解析程序(比如:freedns.asp) 5、二級域名系列程序(包括申請頁:shenqing.htm,添加頁add.asp,解析頁,) 此程序的優點: a,可以限制申請域名的敏感字,比如 hacker,wwww,sex,china等 b, 可以限制申請域名的非法字,比如:!·#¥%……—*()——?‘“/等 c, 每個地址只能申請一個域名。 d,限制申請域名的長度, e, 如果用戶所訪問的域名沒人申請則轉到特定的頁面,本例中的http://www.51bxg.com/miss.html f, 申請了域名:***.yourname.com 可以同時支持:http://***.yourname.com 以及http://www.***.youranme.com 兩個域名的訪問。 一下為系列程序代碼: shenqing.htm <form action=adddns.asp method=post name=Frm onSubmit="return check_input()"> <br> <font color=red>加*號為必填內容</font> <br> 您想注冊的域名: http://<input name="nowurl" size=12& ... sp; style=" BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000; FONT-SIZE: 9pt"> .51bxg.com <br> 你實際的網站地址: <input name="tourl" size=12 style=" BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000; FONT-SIZE: 9pt"> 你要求顯示的title: <input name="company" size=12 style=" BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000; FONT-SIZE: 9pt"> <br> <input type="submit" name="Submit" value=" 提 交 信 息 " style="border:1px double rgb(88,88,88);font:9pt"> <input type="reset" name="Reset" value=" 重 新 填 寫 " style="border:1px double rgb(88,88,88);font:9pt"> </p> </form> 添加記錄頁面add.asp <!--#include file="char.inc"--> <!--#include file="conn.asp"--> <% uID=request.cookies("*****") %> <% dim nowurl,tourl,company,along,pbkey nowurl=trim(request.form("nowurl"))+".51bxg.com" nurl=trim(request.form("nowurl")) tourl=trim(request.form("tourl")) company=trim(request.form("company")) along=20 pbkey="www,sex,admin,w,ww,wwww,hacker,hack" set rs=server.createobject("adodb.recordset") sql="select * from dns where userid='"&uid&"'" rs.open sql,conn,1,1 if not rs.EOF then response.write"很抱歉,你已經申請過二級域名,每個用戶只能申請一個二級域名!<br>你申請的二級域名是:http://"+rs("nowurl") response.end end if set rs=server.createobject("adodb.recordset") sql="select * from dns where nowurl='"&nowurl&"'" rs.open sql,conn,1,1 if not rs.eof then response.write"很抱歉,你申請的域名:http://"+nowurl+"已經被其他公司申請,請另外申請域名。" response.end end if if len(nurl)>along then response.write"很抱歉,你輸入的域名太長,請重新輸入" response.end end if if instr(pbkey,nurl) then response.write"很抱歉,你輸入的域名因為含有敏感字而不管理員屏蔽,請重新輸入。" -------------------------------------------------------------------------------- response.end end if '判斷字符的合法性 if instr(nurl,"~") or instr(nurl,"`") or instr(nurl,"/") or instr(nurl,"?") or instr(nurl,">") or instr(nurl,"<") or instr(nurl,";") or instr(nurl,":") or instr(nurl,"}") or instr(nurl,"{") or instr(nurl,")") or instr(nurl,"(") or instr(nurl,"*") or instr(nurl,"&") or instr(nurl,"^") or instr(nurl,"%") or instr(nurl,".") or instr(nurl,",") or instr(nurl,"'") or instr(nurl,"~") or instr(nurl,"!") or instr(nurl,"$") then response.write"很抱歉,你輸入的域名含有非法字符,請重新輸入,以下字符為非法字符:<br>~ ` / ? > < ; : } { ) ( * & ^ % $ # @ ! " response.end end if set rs=server.createobject("adodb.recordset") sql="select * from ** where theid is null" rs.open sql,conn,3,3 rs.addnew rs("userid")=uID rs("nowurl")=nowurl rs("tourl")=tourl rs("company")=company rs.update response.write"祝賀,申請成功,你馬上就可使用你的域名:http://"+nowurl %> 域名解吸程序: freedns.asp <!--#include file="conn.asp"--> <% dim geturl geturl=replace(Request.ServerVariables("HTTP_HOST"),"www.","") set rs=server.createobject("adodb.recordset") sql="select * from tb where nowurl='"&geturl&"'" rs.open sql,conn,1,1 if rs.eof then response.redirect"http://www.51bxg.com/miss.html" else dim tourl,company tourl=rs("tourl") company=rs("company") %> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=gb2312"> <META CONTENT="text/html; CHARSET=UTF-8" HTTP-EQUIV="Content-Type"> <TITLE><% =company %></TITLE> </HEAD> <frameset frameborder="0" framespacing="0" scrolling="no" border="0" marginheight="0" marginwidth="0" rows="0,*"> <frame scrolling="NO" noresize="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" target="main" name="main" SRC="about:blank"> <frame scrolling="yes" noresize="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" target="main" name="main" SRC="<% =tourl %>"> <noframes> <body> <p>This page uses frames, but your browser doesn't support them.</p></body> </noframes> </frameset> </HTML> <% end if %> |
![]() |
|
Copyright © 一天一點愛戀 | Powered by: 博客園 模板提供:滬江博客 |