我的人生路  
          日歷
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789
          統計
          • 隨筆 - 74
          • 文章 - 57
          • 評論 - 7
          • 引用 - 0

          導航

          常用鏈接

          留言簿(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%>
          posted @ 2005-07-07 16:20 一天一點愛戀 閱讀(145) | 評論 (0)編輯 收藏
           
           如果我們知道一個靜態文件的實際路徑如:http://www.xx.com/download/51windows.pdf,如果服務器沒有作特別的限制設置,我們就可以毫不費力的把它下載下來!當網站提供51windows.pdf下載時,怎么樣才能讓下載者無法得到他的實際路徑呢!本文就來介紹如何使用Asp來隱藏文件的實際下載路徑。

            我們在管理網站文件時,可以把擴展名一樣的文件放在同一個目錄下,起一個比較特別名字,例如放pdf文件目錄為the_pdf_file_s,把下面代碼另存為down.asp,他的網上路徑為http://www.xx.com/down.asp,我們就可以用http://www.xx.com/down.asp?FileName=51windows.pdf來下載這個文件了,而且下載者無法看到這個文件實際下載路徑的!在down.asp中我們還可以設置下載文件是否需要登陸,判斷下載的來源頁是否為外部網站,從而可以做到防止文件被盜鏈。

          示例代碼:

          <%
          From_url = Cstr(Request.ServerVariables("HTTP_REFERER"))
          Serv_url = Cstr(Request.ServerVariables("SERVER_NAME"))
          if mid(From_url,8,len(Serv_url)) <> Serv_url then
          response.write "非法鏈接!" '防止盜鏈
          response.end
          end if

          if Request.Cookies("Logined")="" then
          response.redirect "/login.asp" '需要登陸!
          end if
          Function GetFileName(longname)'/folder1/folder2/file.asp=>file.asp
          while instr(longname,"/")
          longname = right(longname,len(longname)-1)
          wend
          GetFileName = longname
          End Function
          Dim Stream
          Dim Contents
          Dim FileName
          Dim TrueFileName
          Dim FileExt
          Const adTypeBinary = 1
          FileName = Request.QueryString("FileName")
          if FileName = "" Then
          Response.Write "無效文件名!"
          Response.End
          End if
          FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)
          Select Case UCase(FileExt)
          Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
          Response.Write "非法操作!"
          Response.End
          End Select
          Response.Clear
          if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then
          Response.ContentType = "image/*" '對圖像文件不出現下載對話框
          else
          Response.ContentType = "application/ms-download"
          end if
          Response.AddHeader "content-disposition", "attachment; filename=" & GetFileName(Request.QueryString("FileName"))
          Set Stream = server.CreateObject("ADODB.Stream")
          Stream.Type = adTypeBinary
          Stream.Open
          if lcase(right(FileName,3))="pdf" then '設置pdf類型文件目錄
          TrueFileName = "/the_pdf_file_s/"&FileName
          end if
          if lcase(right(FileName,3))="doc" then '設置DOC類型文件目錄
          TrueFileName = "/my_D_O_C_file/"&FileName
          end if
          if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then
          TrueFileName = "/all_images_/"&FileName '設置圖像文件目錄
          end if
          Stream.LoadFromFile Server.MapPath(TrueFileName)
          While Not Stream.EOS
          Response.BinaryWrite Stream.Read(1024 * 64)
          Wend
          Stream.Close
          Set Stream = Nothing
          Response.Flush
          Response.End
          %>

          posted @ 2005-07-07 16:19 一天一點愛戀 閱讀(123) | 評論 (0)編輯 收藏
           

          會員注冊以后,有些會員可能會遇到忘記登錄密碼的問題,因而網站具備“找回密碼”功能不僅是必須的,而且是服務貼心的具體表現之一。在此,levitian寫了一個“找回密碼”的小教程,供初學動態網站設計的朋友們借鑒,希望對大家有所幫助。

          ●相關說明:
          ·levitian假設您已經作好了會員系統,接下來準備作“找回密碼”功能但還沒有作,或者您不知道怎么作這個功能,那么剛好可以看看本教程。
          ·國內大多數服務器都支持Jmail郵件組件,因而levitian就使用該組件實現郵件發送功能;
          ·傳統的“找回密碼”功能要使用“密碼取回問題”和“密碼取回答案”等字段,但levitian認為大可不必這么繁瑣,反正最終目的是將密碼發進用戶的郵箱里,而用戶的郵箱只有自己可以收發郵件,那么以上這兩個字段就可以省略了。實際上只要填上用戶名和自己的郵箱,按“找回密碼”,啟動Jmail郵件組件把密碼發至用戶郵箱--就這么簡單!
          ·levitian用的是Dreamweaver MX,您用Dreamweaver UltraDev當然也沒問題了。
          ·本系統主要用到了DW服務器行為中的“登錄用戶”和“插入”菜單中的“文件頭標簽”中的“刷新”子功能。用戶不知道登錄密碼沒關系,他可以用自己的用戶名和郵箱找回密碼,但如果該用戶的郵箱是假的(胡填的),或根本沒有在自己的注冊資料中填郵箱,或者他輸入了別人的郵箱,那么他也就無法進入找回密碼的頁面,當然也就無法找回自己的密碼了~

          好了,說了一大堆廢話:) 趕快GO →

          ●步驟一:制作相關的ASP頁面
          我們需要增加三個頁面,一個頁面是“找回密碼登錄頁面”,這里我命名為getbackpass.asp;另一個是“密碼發送成功報告頁面”,這里我命名為getbackpassok.asp;第三個頁面為郵箱不存在或用戶名不正確時顯示錯誤信息的頁面,這里我命名為getbackpassfail.asp。

          ●步驟二:在會員登錄頁面增加“找回密碼”文本型鏈接或圖片型鏈接
          在會員登錄界面中輸入文本“找回密碼”或者插入一張圖片,將其鏈接至找回密碼登錄頁面getbackpass.asp;如果您想把“找回密碼”鏈接放在其它頁面,當然沒問題了。

          ●步驟三:制作找回密碼登錄頁面getbackpass.asp
          ·打開找回密碼登錄頁面getbackpass.asp,建立表單域,插入兩個文本域,第一個命名為MemberName,第二個命名為MemberEmail(您的會員信息數據表中的會員姓名字段和會員郵箱字段如不是MemberName和MemberEmail,請修改成相應的字段名),接下來插入一個“按鈕”,命名為“取回密碼”。
          ·打開服務器行為面板,點擊“+”,選擇“用戶身份驗證”中的“登錄用戶”,在“登錄用戶”面板中,我主要說說以下項目的設置:
          使用連接驗證:我們選擇已經定義好的DSN連接
          表格:我們選擇會員注冊信息表單
          用戶名列:我們選擇MemberName
          密碼列:我們選擇MemberEmail
          如果登錄成功轉到:我們選擇getbackpassok.asp
          如果登錄失敗轉到:我們選擇getbackpassfail.asp
          基于以下項限制訪問:我們選擇“用戶名和密碼”
          OK!可以按“確定”按鈕了。
          ·加入表單驗證代碼
          為防止用戶不填表單就登錄,可加入以下代碼,讓用戶必須填寫內容:
          將DW切換到源代碼視圖,首先,將以下代碼加入<head> </head>之間:

          <script language="javascript">
          <!--
          function checkdata() {
          if (document.form1.MemberName.value=="") {
          window.alert ("請輸入用戶名 !")
          return false
          }
          if (document.form1.MemberEmail.value=="") {
          window.alert ("請輸入您的郵箱 !")
          return false
          }
          return true
          }
          //-->
          </script>

          接下來,在<form>標簽里插入以下代碼:onSubmit="return checkdata()"
          這樣,表單驗證就作好了。

          ●步驟四:制作密碼發送成功報告頁面getbackpassok.asp
          ·打開密碼發送成功報告頁面getbackpassok.asp,輸入文本“密碼已發至您的郵箱中,請查詢密碼后登錄本站!”
          ·建立數據集member,您當然可以用其它的數據集名稱:
          連接:一欄選擇您定義的DSN連接
          表格:一欄選擇會員信息數據表member
          列:一欄選定會員ID、用戶名、密碼和郵箱這四個字段
          篩選:MemberName=階段變量MM_Username
          排序:不用填
          至此,數據集就建立好了。在篩選里,我們之所以用階段變量(Session Variable),是因為我們需要篩選出找回密碼的用戶。使用DW服務器行為的“登錄用戶”行為以后,登錄者的名稱(數據庫中的MemberName字段)就自動保存在名為MM_Username的Session變量中。這們使用“MemberName=階段變量MM_Username”作為篩選條件,自然可以篩選出想找回密碼的用戶了。
          ·接下來我們加入Jmail郵件發送代碼。將Dreamweaver設計界面切換到顯示代碼視圖,找見如下代碼:
          <%
          Dim member__MMColParam
          member__MMColParam = "1"
          If (Session("MM_Username") <> "") Then
          member__MMColParam = Session("MM_Username")
          End If
          %>
          <%
          set member = Server.CreateObject("ADODB.Recordset")
          member.ActiveConnection = MM_spsguavaskirtdate_STRING
          member.Source = "SELECT MemberID, MemberName, Password, MemberEmail FROM Member WHERE MemberName = '" + Replace(member__MMColParam, "'", "''") + "'"
          member.CursorType = 0
          member.CursorLocation = 2
          member.LockType = 3
          member.Open()
          member_numRows = 0
          %>
          這是數據集形成的代碼,然后在倒數第二行,即%>上一行,插入以下Jmail組件代碼:
          Set JMail = Server.CreateObject("JMail.SMTPMail")
          JMail.ServerAddress = "mail.emaichina.net:25"
          JMail.Sender = "emai@emaichina.net"
          JMail.Subject = "您的登錄密碼"
          JMail.AddRecipient(member.Fields.Item("MemberEmail").Value)
          JMail.Body = "尊敬的用戶您好,首先感謝您使用我們的服務!." & vbCrLf & vbCrLf
          JMail.Body = JMail.Body & "您的用戶名是:" &(member.Fields.Item("MemberName").Value) & vbCrLf
          JMail.Body = JMail.Body & "您的注冊郵箱是:" &(member.Fields.Item("MemberEmail").Value) & vbCrLf
          JMail.Body = JMail.Body & "您的登錄密碼是:" &(member.Fields.Item("Password").Value) & vbCrLf
          JMail.Body = JMail.Body & "請妥善保管您的密碼,如再次遺忘密碼,請登錄至http://www.emaichina.net/member/memberpage/getbackpass.asp 取回您的密碼,謝謝您使用本系統。" & vbCrLf
          JMail.Body = JMail.Body & "順祝商祺!" & vbCrLf
          JMail.Body = JMail.Body & "譯媒藝術咨詢有限公司"
          JMail.Priority = 3
          JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
          JMail.Execute

          以上代碼簡單說明如下:
          JMail.ServerAddress= 后面填上您的SMTP服務器,如"mail.emaichina.net:25,千萬別忘了填端口號:25;
          JMail.Sender= 后面填上您的郵箱,如emai@emaichina.net,請確保此郵箱可以正常收發郵件;
          JMail.Subject = 后面輸入信件標題,如"您的登錄密碼",切記,文本之間一定要加上“"”;
          JMail.AddRecipient后面插入數據集member中的郵箱字段,如(member.Fields.Item("MemberEmail").Value);
          JMail.Body =后面輸入信件的稱謂部分,如: "尊敬的用戶您好,首先感謝您使用我們的服務!." & vbCrLf & vbCrLf
          JMail.Body = 后面開始輸入信件內容,如果是動態內容,那么插入數據集中的相應字段,如果是靜態內容,則直接輸入文本即可。每一段使用一個JMail.Body =,結尾都加上vbCrLf,有多少段就拷貝粘貼多少個JMail.Body =,這樣就可以寫出來一封完整的找回密碼回復信。
          關于vbCrLf說明:vbCrLf的作用是換行,您想空一行就加一個 vbCrLf,想空兩行就加兩個vbCrLf…但在vbCrLf和vbCrLf之間一定要加“&”符號將它們隔開,否則會出現錯誤提示。

          ●制作顯示錯誤信息頁面getbackpassfail.asp
          如果用戶名、密碼錯誤或用戶名和密碼根本不存在,那么系統會轉到顯示錯誤信息頁面,并且在2秒后自動返回“找回密碼登錄頁面”。下面是制作方法:
          打開getbackpassfail.asp,在頁面中輸入文本“您的郵箱不存在,請確認您在注冊資料中填寫了郵箱! ”,然后,打開DW軟件菜單中的→插入”→“文件頭標簽”→“刷新”,“延遲”填上2,就是2秒,如果您想讓頁面保持時間更長,也可以填3秒、5秒甚至10秒;“操作”選擇“轉到URL”,填上getbackpass.asp,這樣這個頁面2秒鐘后就會自動回到“找回密碼登錄頁面”了。
          OK!這個頁面就做好了,很簡單!

          ●測試這個找回密碼系統
          以上系統作好后,您可以測試一下。如果您在本地測試,并且不是用的Win98操作系統,那么需要安裝Jmail郵件組件(這個組件可去下載網站下載,是免費的);如果您用的是Win98操作系統或您的計算機中沒有安裝Jmail郵件組件,那么,可把這個系統上傳到支持Jmail郵件組件的服務器空間上,試著找回密碼,如果沒問題,說明您成功了。如果有問題,請仔細查看制作步驟或代碼有沒有錯誤,這里祝您好運!
          說明:學會“找回密碼系統”的制作方法后,您可以舉一反三作一個會員注冊后的郵件自動回復系統,也相當簡單,大家可以試一下。

          ●“找回密碼”郵件樣式
          以下是levitian測試本系統后,在Foxmail收到的郵件,樣式基本上這樣的:
          ------------------------------------------------
          尊敬的用戶您好,首先感謝您使用我們的服務!.

          您的用戶名是:levi
          您的注冊郵箱是:levitian@163.com
          您的登錄密碼是:741127
          請妥善保管您的密碼,如再次遺忘密碼,請登錄至member/memberpage/getbackpass.asp 取回您的密碼,謝謝您使用本系統。
          順祝商祺!

          posted @ 2005-07-07 15:30 一天一點愛戀 閱讀(185) | 評論 (0)編輯 收藏
           

          有一頁填表的頁面,其中有幾個下拉表單是通過一個表的某個字段動態
          生成,比如省下面的城市名,希望選擇某一個省即可自動在另一下拉表
          單內生成城市名,.....然后提交給asp處理加入到另外一個表內。

          <form name=f1 METHOD="POST">
          <%
          OpenDB objConn, "xxxx"
          Set RSClass = objConn.Execute("SELECT * FROM class Order by fldClass")
          If RSClass.EOF Then
          Response.Write "沒有記錄。<BR>"

          Else

          Response.Write "<SELECT NAME=""class"" style=""FONT-SIZE: 9pt"" SIZE=10" & _
          " ONCHANGE=""classselected(this);"" >"
          sjavascript = "function classselected(elem){" &_
          vbCrlf & _
          "for (var i = document.f1.sort.options.length; i >= 0; i--){" & vbCrlf & _
          "document.f1.sort.options[i] = null;" & _
          vbCrlf
          Do Until RSClass.EOF
          If sLastClass <> RSClass("fldClass") Then
          sLastClass = RSClass("fldClass")
          Response.Write "<OPTION VALUE=" & RSClass("fldID") & ">" & sLastClass & "</OPTION>"
          sjavascript = sjavascript & "}" & vbCrlf & _
          "if (elem.options[elem.selectedIndex].value==" & _
          RSClass("fldID") & "){" & vbCrlf
          End If
          sjavascript = sjavascript & _
          "document.f1.sort.options[document." & _
          "f1.sort.options.length] = new Option('" & _
          RSClass("fldSort") & "','" & RSClass("fldID") & "');" & _
          vbCrlf
          RSClass.MoveNext
          Loop
          Response.Write "</SELECT>"
          Response.Write "<SELECT NAME=""sort"" style=""FONT-SIZE: 9pt"" SIZE=10>"
          Response.Write "<OPTION>[請選擇]</OPTION>"
          Response.Write "</SELECT>"

          sjavascript = sjavascript & vbCrlf & "}" & vbCrlf & "}" & vbCrlf
          Response.Write "<SCR" & "IPT LANGUAGE=""javascript"">" & vbCrlf
          Response.Write sjavascript & vbCrlf & "</SCR" & "IPT>" & vbCrlf
          End If
          RSClass.Close
          Set RSClass = Nothing%>
          </form>

          posted @ 2005-07-07 15:27 一天一點愛戀 閱讀(255) | 評論 (0)編輯 收藏
           

          在ASP中加密方法有對應的解密方法好象不多,現在根據前輩資料整理出在asp中加密與解密函數

          rsa.asp
          <%
          rem 在ASP中實現加密與解密,加密方法:根據RSA
          rem 聯系:hnsoso@sina.com
          Class clsRSA

            Public PrivateKey
            Public PublicKey
            Public Modulus
            
            
            
            Public Function Crypt(pLngMessage, pLngKey)
              On Error Resume Next
              Dim lLngMod
              Dim lLngResult
              Dim lLngIndex
              If pLngKey Mod 2 = 0 Then
                lLngResult = 1
                For lLngIndex = 1 To pLngKey / 2
                  lLngMod = (pLngMessage ^ 2) Mod Modulus
                  ' Mod may error on key generation
                  lLngResult = (lLngMod * lLngResult) Mod Modulus
                  If Err Then Exit Function
                Next
              Else
                lLngResult = pLngMessage
                For lLngIndex = 1 To pLngKey / 2
                  lLngMod = (pLngMessage ^ 2) Mod Modulus
                  On Error Resume Next
                  ' Mod may error on key generation
                  lLngResult = (lLngMod * lLngResult) Mod Modulus
                  If Err Then Exit Function
                Next
              End If
              Crypt = lLngResult
            End Function

            Public Function Encode(ByVal pStrMessage)
              Dim lLngIndex
              Dim lLngMaxIndex
              Dim lBytAscii
              Dim lLngEncrypted
              lLngMaxIndex = Len(pStrMessage)
              If lLngMaxIndex = 0 Then Exit Function
              For lLngIndex = 1 To lLngMaxIndex
                lBytAscii = Asc(Mid(pStrMessage, lLngIndex, 1))
                lLngEncrypted = Crypt(lBytAscii, PublicKey)
                Encode = Encode & NumberToHex(lLngEncrypted, 4)
              Next
            End Function
            
            Public Function Decode(ByVal pStrMessage)
              Dim lBytAscii
              Dim lLngIndex
              Dim lLngMaxIndex
              Dim lLngEncryptedData
              Decode = ""
              lLngMaxIndex = Len(pStrMessage)
              For lLngIndex = 1 To lLngMaxIndex Step 4
                lLngEncryptedData = HexToNumber(Mid(pStrMessage, lLngIndex, 4))
                lBytAscii = Crypt(lLngEncryptedData, PrivateKey)
                Decode = Decode & Chr(lBytAscii)
              Next
            End Function
            
            Private Function NumberToHex(ByRef pLngNumber, ByRef pLngLength)
              NumberToHex = Right(String(pLngLength, "0") & Hex(pLngNumber), pLngLength)
            End Function

            Private Function HexToNumber(ByRef pStrHex)
              HexToNumber = CLng("&h" & pStrHex)
            End Function

          End Class
          %>

          test.asp
          <!--#INCLUDE FILE="RSA.asp"-->
          <%
          function Encryptstr(Message)
          Dim LngKeyE
          Dim LngKeyD
          Dim LngKeyN
          Dim StrMessage
          Dim ObjRSA


            LngKeyE = "32823"
            LngKeyD = "20643"
            LngKeyN = "29893"
            StrMessage = Message
            
            Set ObjRSA = New clsRSA
            
           
                ObjRSA.PublicKey = LngKeyE
                ObjRSA.Modulus = LngKeyN
                Encryptstr = ObjRSA.Encode(StrMessage)
            Set ObjRSA = Nothing
          end function


          function decryptstr(Message)
          Dim LngKeyE
          Dim LngKeyD
          Dim LngKeyN
          Dim StrMessage
          Dim ObjRSA


            LngKeyE = "32823"
            LngKeyD = "20643"
            LngKeyN = "29893"
            StrMessage = Message
            
            Set ObjRSA = New clsRSA

                ObjRSA.PrivateKey =LngKeyD
                ObjRSA.Modulus=LngKeyN
                decryptstr=ObjRSA.Decode(StrMessage)
            Set ObjRSA = Nothing
          end function

          dim last,first
          first="sohu"
          Response.Write "加密前為:"&first
          last=Encryptstr(first)
          Response.Write "加密后為"&last
          Response.Write "解密后為" &decryptstr(last)

          %>

          posted @ 2005-07-07 15:24 一天一點愛戀 閱讀(154) | 評論 (0)編輯 收藏
           

          <SCRIPT language="javascript">
            function IfWindowClosed()
            {  
              var win = null;
              try
              {
                window.opener.name = "ss";
                if ( window.opener.name != "ss" )
                {
                  win = window.open("quit.asp","","width=100,height=100,left=10000,top=10000");
                  window.setTimeout("window.close();",0);
                }
                window.opener.name = "";
              }
              catch(e)
              {
                win = window.open("quit.asp","","width=100,height=100,left=10000,top=10000");
                window.setTimeout("window.close();",0);
              }
            }
            
            window.setInterval("IfWindowClosed()",100);
            window.setTimeout("window.close();",510);
          </SCRIPT>
          ---------------

          用onunload事件打開上面的文件

          quit.asp為保存數據的文件,上面的文件用來檢測窗口是關閉還是刷新

          ie5兼容,以前使用 window.opener.closed來判斷,ie5不支持closed 屬性。
          上面的代碼經過多次測試,暫時沒有發現問題

          posted @ 2005-07-07 15:23 一天一點愛戀 閱讀(197) | 評論 (0)編輯 收藏
           
          <%  Set pop3 = Server.CreateObject( "JMail.POP3" )
            
            '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 & "&nbsp;(<a href=""mailto:"& re.EMail &""">" & re.EMail & "</a>)" &
          separator
                  else
                      ReCC = ReTo & re.Name & "&nbsp;(<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

          %>
          posted @ 2005-07-07 15:12 一天一點愛戀 閱讀(183) | 評論 (0)編輯 收藏
           
          提交時可能會有人修改script從本地提交,這樣存在安全提交的問題,所以應該要求從服務器斷路徑提交,其他地址提交提交無無效:
          <%
          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

          posted @ 2005-07-07 15:11 一天一點愛戀 閱讀(151) | 評論 (0)編輯 收藏
           
          其實想實現這種功能很簡單,首先要上傳一個RAR的解壓程序,就是RAR自己的解壓程序,只需要它的核心 
          程序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文件的。 
          以前不知道是否有前輩們發表過這些文章,但那位兄弟有興趣的可以以用這種方法來實現諸多類似與這樣的程序,希望你們可以找到一些更好的方法。 
          posted @ 2005-07-07 15:02 一天一點愛戀 閱讀(155) | 評論 (0)編輯 收藏
           
          要達到二級名的效果,必須一下條件以及流程:
          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 %>
          posted @ 2005-07-07 15:01 一天一點愛戀 閱讀(165) | 評論 (0)編輯 收藏
          僅列出標題
          共8頁: 上一頁 1 2 3 4 5 6 7 8 下一頁 
           
          Copyright © 一天一點愛戀 Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 许昌县| 双柏县| 来安县| 金山区| 措美县| 舟山市| 余庆县| 东安县| 滦平县| 博乐市| 阿拉尔市| 汤阴县| 双牌县| 巴青县| 江川县| 博乐市| 酒泉市| 岐山县| 新昌县| 绍兴县| 娱乐| 尖扎县| 陆川县| 明溪县| 临夏市| 遂平县| 巴林左旗| 海南省| 承德县| 射洪县| 闻喜县| 湘潭市| 南汇区| 平利县| 新河县| 修武县| 九龙坡区| 尼勒克县| 崇文区| 湟源县| 博爱县|