一 些 ASP 小 源 程 序

Active Server Pages
Password Script

1   
2Sub FormInput() 
 1<form action="logon.asp" method="post">
 2<center>
 3<h1>Generic Logon</h1>   
 4User Name:<input name="username" size="20" type="text"/>
 5<br/><br/>   
 6Password:<input name="password" size="20" type="password"/>
 7<br/><br/>
 8<input name="submit" type="submit" value="Submit"/>
 9</center>
10</form>
1 End Sub 
 1   
 2' *********** Password Login Code *********************   
 3' *********** programmed by Robert Robbins ************   
 4' *********** First Version 03/28/99 ******************   
 5' *****************************************************   
 6' Call Input Form subroutine   
 7FormInput()   
 8  
 9' Create session variable. Username needed for filename.asp   
10Session("user") = ""   
11  
12' Initialize boolean flags to false   
13correct_name = False   
14correct_password = False   
15  
16' Connect to table in database   
17Set cn = Server.CreateObject("ADODB.Connection")   
18Set rs = Server.CreateObject("ADODB.Recordset")   
19cn.Open "DSN Name"   
20rs.Open "Select * From TableName",cn,adOpenStatic,adLockPessimistic   
21  
22' Test for correct username and password   
23If Request.Form("submit") > "" Then   
24Do While Not rs.EOF   
25' Compare form input to password database recordset values   
26If Request.Form("username") = rs("username") Then   
27correct_name = True   
28End If   
29If Request.Form("password") = rs("password") Then   
30correct_password = True   
31End If   
32rs.MoveNext   
33Loop   
34  
35If correct_password = True And correct_name = True Then   
36' If password and username are correct, jump to DataEntry.asp   
37' Note: chr(34) is the double quotes character   
38Session("user") = Request.Form("username")   
39Response.write "

<script "="" &="" chr(34)="" javascript"="" language=" &amp; chr(34) &amp; ">"
Response.write "window.location = " & chr(34) & "DataEntry.asp" & chr(34) & """
Response.write "</script>

1"   
2Else   
3' If password or username is incorrect, write JavaScript code in HTML for an alert   
4dialog box   
5Response.write "

<script "="" &="" chr(34)="" javascript"="" language=" &amp; chr(34) &amp; ">"
Response.write "alert(" & chr(34) & "Access Denied!" & chr(34) & ");"
Response.write "</script>

1"   
2End If   
3rs.Close   
4End If   

Password Protect Script

1   
2' Set local variable username to Session variable user   
3username = Session("user")   
4  
5' If username is an empty string, the user did not use logon.asp to login   
6If username = "" Then   
7Response.write "Sorry, you are not logged in!

<br/>

1"   
2Session.Abandon   
3Response.End   
4End If   

Email Script
Newline = chr(13) & chr(10)
Set Mailer = Server.CreateObject("CDONTS.NewMail")
Mailer.To = "" & Request.Form("Email") & ""
Mailer.From = "" & "[email protected]" & ""
Mailer.Subject = "" & "Testing Automated Email" & ""
Mailer.Body = "" & "My email message" & Newline & "Second line" & ""
Mailer.Send
Set Mailer = Nothing
SQL Server Connection

1   
2Set cn = Server.CreateObject("ADODB.Connection")   
3Set rs = Server.CreateObject("ADODB.Recordset")   
4strConn = "driver={SQL Server};server=Pentium;uid=sa;pwd=;database=Test"   
5cn.Open strConn   

Windows Script Host
' Windows Script Host File
' programmed by Robert S. Robbins
' Open database connecection and get recordset
Const adOpenForwardOnly = 0
Const adLockPessimistic = 2
Set cn = WScript.CreateObject("ADODB.Connection")
Set rs = WScript.CreateObject("ADODB.Recordset")
cn.Open "DSN Name"
rs.Open "Select * From TableName",cn,adOpenForwardOnly,adLockPessimistic
While Not rs.EOF
message = rs("Message")
MsgBox message,64,"Database Message"
rs.MoveNext
Wend

VBScript 5.0 Regular Expression

 1   
 2Set objFile = Server.CreateObject("Scripting.FileSystemObject")   
 3Set inFile = objFile.OpenTextFile("D:\Temp\test.txt", 1)   
 4strInput = inFile.ReadALL   
 5inFile.Close   
 6Set myTest = new RegExp   
 7myTest.Pattern = "\w+,"   
 8myTest.Global = True   
 9myTest.IgnoreCase = True   
10Set myCollection = myTest.Execute(strInput)   
11For Each element In myCollection   
12Response.write element & "

<br/>

1"   
2Next   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus