List all your session changes:
<%@ Language=VBScript %>
<% Option Explicit %>
<%
"I used it in your program in total" & & _
" Session variable<P>"
Dim strName, iLoop
For Each strName in
'Just determine whether a Session variable is an array
If IsArray(Session(strName)) then
'If it is an array, then list all the array elements contents
For iLoop = LBound(Session(strName)) to UBound(Session(strName))
strName & "(" & iLoop & ") - " & _
Session(strName)(iLoop) & "<BR>"
Next
Else
'If it is not an array, then directly display
strName & " - " & (strName) & "<BR>"
End If
Next
%>
ASP function to send emails using CDONTS
<%
'Last Updated By Recon On 05/14/2001
'On Error Resume Next
'Use CDONTS component to send emails on Win2k
'Send regular email
SendMail "admin@", "iamchn@", "Normal Mail!", "Please check the attatchment!", 2, 0, "C:\"
'Send HTML email
Dim m_fso, m_tf
Dim m_strHTML
Set m_fso = ("")
Set m_tf = m_fso.OpenTextFile("C:\", 1)
m_strHTML = m_tf.ReadAll
'Write m_strHTML
Set m_tf = Nothing
Set m_fso = Nothing
SendMail "admin@", "iamchn@", "HTML Mail!", m_strHTML, 2, 1, Null
'Parameter description
'strFrom : Sender Email
'strTo : Recipient Email
'strSubject : Theme of the letter
'strBody : The text of the letter
'lngImportance : The importance of letters
' : 0 - Low importance
' : 0 - Medium importance (default)
' : 0 - High importance
'lngAType : Letter format
' : When it is 1, use the email body as HTML (HTML email can be sent at this time)
'strAttach : The path to the attachment
Sub SendMail(strFrom, strTo, strSubject, strBody, lngImportance, lngAType, strAttach)
Dim objMail
Set objMail = ("")
With objMail
.From = strFrom
.To = strTo
.Subject = strSubject
.Body = strBody
.Importance = lngImportance
If lngAType = 1 Then
.BodyFormat = 0
.MailFormat = 0
End If
If IsEmpty(strAttach) = False And IsNull(strAttach) = False Then
.AttachFile strAttach
End If
.Send
End With
Set objMail = Nothing
End Sub
%>
Handle drives and folders
Using the FileSystemObject (FSO) object mode, you can process drives and folders in a planned manner, just like you can handle them interactively in Windows Explorer. You can copy and move folders, get information about drives and folders, and more.
Get information about the drive
You can use the Drive object to obtain information about various drives that are physically connected to the system or over a network. Its properties can be used to obtain the following information:
Total capacity of the drive, in bytes (TotalSize property)
What is the available space of the drive, in bytes (AvailableSpace or FreeSpace attribute)
Which number is assigned to the drive (DriveLetter attribute)
What is the type of drive, such as removable, fixed, networked, CD-ROM or RAM disk (DriveType attribute)
The serial number of the drive (SerialNumber attribute)
The file system types used by the drive, such as FAT, FAT32, NTFS, etc. (FileSystem attribute)
Is the drive usable (IsReady property)
Share and/or volume name (ShareName and VolumeName properties)
The path or root folder of the drive (Path and RootFolder properties)
Please examine the sample code to understand how to use these properties in FileSystemObject.
Drive object usage example
Use the Drive object to collect information about the drive. In the following code, there is no reference to the actual Drive object; instead, use the GetDrive method to obtain a reference to the existing Drive object (in this example, drv).
The following example demonstrates how to use the Drive object in VBScript:
Sub ShowDriveInfo(drvPath)
Dim fso, drv, s
Set fso = CreateObject("")
Set drv = ((drvPath))
s = "Drive " & UCase(drvPath) & " - "
s = s & & "<br/>"
s = s & "Total Space: " & FormatNumber( / 1024, 0)
s = s & " Kb" & "<br/>"
s = s & "Free Space: " & FormatNumber( / 1024, 0)
s = s & " Kb" & "<br/>"
s
End Sub
The following code shows that the same function is implemented in JScript:
function ShowDriveInfo1(drvPath)
{
var fso, drv, s ="";
fso = new ActiveXObject("");
drv = ((drvPath));
s += "Drive " + ()+ " - ";
s += + "<br/>";
s += "Total Space: " + / 1024;
s += " Kb" + "<br/>";
s += "Free Space: " + / 1024;
s += " Kb" + "<br/>";
(s);
}
Process folders
In the following table, ordinary folder tasks and methods of executing them are described.
Task Method
Create a folder.
Delete the folder. or
Move folders. or
Copy the folder. or
Search the name of the folder.
If the folder exists on the drive, find it.
Obtain an instance of an existing Folder object.
Find the parent folder name of the folder.
Find the path to the system folder.
Please check the sample code to see how many methods and properties are used in FileSystemObject.
The following example demonstrates how to use Folder and FileSystemObject objects in VBScript to manipulate folders and obtain information about them:
Sub ShowFolderInfo()
Dim fso, fldr, s
' Get an instance of FileSystemObject.
Set fso = CreateObject("")
' Get the Drive object.
Set fldr = ("c:")
' Print the parent folder name.
"Parent folder name is: " & fldr & "<br/>"
' Print the driver name.
"Contained on drive " & & "<br/>"
' Print the root file name.
If = True Then
"This is the root folder." & ""<br/>"<br/>"
Else
"This folder isn't a root folder." & "<br/><br/>"
End If
' Create a new folder with the FileSystemObject object.
("C:\Bogus")
"Created folder C:\Bogus" & "<br/>"
' Print the basic name of the folder.
"Basename = " & ("c:\bogus") & "<br/>"
' Delete the newly created folder.
("C:\Bogus")
"Deleted folder C:\Bogus" & "<br/>"
End Sub
The following example shows how to use Folder and FileSystemObject objects in JScript:
function ShowFolderInfo()
{
var fso, fldr, s = "";
// Get an instance of FileSystemObject.
fso = new ActiveXObject("");
// Obtain the Drive object.
fldr = ("c:");
// Print the parent folder name.
("Parent folder name is: " + fldr + "<br/>");
// Print the driver name.
("Contained on drive " + + "<br/>");
// Print the root file name.
if ()
("This is the root folder.");
else
("This folder isn't a root folder.");
("<br/><br/>");
// Create a new folder with the FileSystemObject object.
("C:\\Bogus");
("Created folder C:\\Bogus" + "<br/>");
// Print the basic name of the folder.
("Basename = " + ("c:\\bogus") + "<br/>");
// Delete the newly created folder.
("C:\\Bogus");
("Deleted folder C:\\Bogus" + "<br/>");
}
ASP paging function
Function ExportPageInfo(ByRef rs,curpage,i,LinkFile)
Dim retval, j, pageNumber, BasePage
retval = "Things" & curpage & "Page/Total" & & "Page "
retval = retval & "This page" & i & "Note/Total" & & "Note "
If curpage = 1 Then
retval = retval & "Home Previous Page"
Else
retval = retval & "<a href='" & LinkFile & "page=1'>Home</a> <a href='" & LinkFile & "page=" & cstr(curpage - 1) & "'>Previous Page</a> "
End If
If curpage = Then
retval = retval & "Last page Last page"
Else
retval = retval & "<a href='" & LinkFile & "page=" & cstr(curpage + 1) & "'>Last Page</a> <a href='" & LinkFile & "page=" & cstr() & "'>Last Page</a>"
End if
retval = retval & "<br/>"
BasePage = (curpage \ 10) * 10
If BasePage > 0 Then retval = retval & " <a href='" & LinkFile & "page=" & (BasePage - 9) & "'><<</a>"
For j = 1 to 10
pageNumber = BasePage + j
If PageNumber > Then Exit For
If pageNumber = Cint(curpage) Then
retval = retval & " <font color='#FF0000'>" & pageNumber & "</font>"
Else
retval = retval & " <a href='" & LinkFile & "page=" & pageNumber & "'>" & pageNumber & "</a>"
End If
Next
If > BasePage Then retval = retval & " <a href='" & LinkFile & "page=" & (BasePage + 11) & "'>>></a>"
ExportPageInfo = retval
End Function
Application
<%
"SELECT * FROM news ORDER BY addtime DESC", conn, 1, 1
if <> 0 then
"Database operation failed:"&
else
if and then
"No record"
else
%>
<div align="center">
<center>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr class="big">
<td width="60%">News Title</td>
<td width="25%" align="center">Date</td>
<td width="15%" align="center">Operation</td>
</tr>
<%
= 10
= curpage
for i = 0 to 9
%>
<tr>
<td><%= adoPageRS("title") %></td>
<td align="center">
<% = adoPageRS("addtime") %>
</td>
<td align="center"><a href='?action=edit&id=<%= adoPageRS("id")%>'>Edit</a>
<a href='javascript:confirmDel(<%= adoPageRS("id") %>)'>Delete</a></td>
</tr>
<%
if then
i = i + 1
exit for
End If
next
%>
<tr align="center">
<td colspan="3">
<% = ExportPageInfo(adoPageRS, curpage, i, "?") %>
</td>
</tr>
</table>
</center>
</div>
Calling an image in SQL from ASP:
How to deal with images in ASP. When programming with ASP, images are often used. There are many ways to simply process an image from the database, and it is not difficult. You can see the following code: Here suppose you have a database name: PUBS, there is a table called: PUB_INFO in the database, and there is a BLOB column of LOGO in the table. We found photos of people with PUB_ID=0736. FILE: ****************************** < %@ LANGUAGE="VBSCRIPT" %> < % ' Clear out the existing HTTP header information = 0 = TRUE ' ' Change the HTTP header to reflect that an image is being passed. = "image/gif" Set cn = ("") ' The following op en line assumes you have set up a System DataSource ' by the name of myDSN. "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs" Set rs = ("SELECT logo FROM pub_info WHERE pub_id='0736'") rs("logo") %> ************************************ Execute this ASP file to see the images you have in the database. But if you process text and images at the same time, it will be a bit difficult: - (For example: for an enterprise's personnel management, the backend database can be SYBASE or SQL SERVER, etc. (I use SQL SERVER here) When you need to use the BROWSE/SERVER method within the enterprise, that is, when you use a browser to view employee personal information, you must process text information and also use skills about images. Question The problem is that when you display text information, CONTENT="TEXT/HTML" in HTML HEAD, and the image display must be CONTENT="IMAGE/GIF" or CONTENT="IMAGE/JPEG". Therefore, you cannot process both the text information and the image with just one ASP file. The solution is: use a separate ASP file to process the image, and then Call this ASP file in the ASP file that processes text information. Here I will introduce my solution to you. I hope you will discuss it together: Environment: WINNT4.0 SQL SERVER IIS3.0 Database name: RSDA Table name: RSDA_TABLE Purpose: Find out the information of the person with ID=00001 from RSDA_TABLE, including name, age and photos. First Step: Create a query form: ****************************************** < html> < head> < /head> < body> < form method="POST" action=""> < p>Please enter the number: < input type="text" name="T1" size="20"> < input type="submit" value="submit" name="B1"> < /form> < /body> *************************** Second step: establish *************************************** * < html> < head> < meta http-equiv="content-type" content="text/html;charset=gb2312"> < title>Query results< /title> < /head> < body bgColor=Azure> < % session ("RSDA_ID")=("T1") 'Here I used a SESSION variable to call temp_id=session("RSDA_ID") < font size=4 color=OrangeRed> Query result: < /font> < %set conntemp=("") "dsn=RSDA;uid=sa;pwd=SA" set rstemp=("select * from RSDA_TABLE where rsda='"&temp_id&"'") % > < % 'put headings on the table of field names nobody="Sorry! There is no information you are looking for in our database! "%> 'Just determine whether there is this person < %if then % > < font size="5" color=OrangeRed> < %(nobody)% >< /font> < %else% > < div align="center"> < table border="1" width="73%" height="399"> < td width="21%" height="49" align="center">< p align="center">Name< /td> < td width="30%" height="49" align="center"> < font size=4 color=OrangeRed>< /font>< /td> < /td> < /td> < p align="center">age < td width="30%" height="47" align="center"> < font size=4 color=OrangeRed>< %=rstemp(0)% >< /font>< /td> < /tr> < td width="49%" height="146" rowspan="3" colspan="2"> < im g src="">< /td> ' is the ASP file we are going to create that specializes in processing images. < /tr> < /table> < /center>< /div> set rtemp=nothing set conntemp=nothing % > < /BODY> < /HTML> ************************ The third step: create an ASP file that processes images. () ************************************ < % = TRUE ' Open database Set conntemp = ("" ) "dsn=RSDA;uid=sa;pwd=SA" 'change http header = "image/jpeg" ' or "IMAGE/GIF" ' Get picture TEMP_ID=session("RSDA_ID") Set Rs = ("SELECT photo from RSDA_table where ID='"&TEMP_ID&"'") Rs("photo") % > ****************************** The main thing here is to use a SESSION variable to implement two querying of the same condition. As I mentioned above, you can achieve that a page has both text and images with just a few changes!
Some things that are often used by asp,
I usually use the following things (copy)
<%=("remote_addr")%>
FOR each item in
tempvalue=trim(Request(item))
tempvalue=Replace(tempvalue,chr(13)&chr(10),"<br/>")
tempvalue=Replace(tempvalue,"<br/><br/>","<br/>")
if tempvalue="" then tempvalue=0
Execute item&"="""&tempvalue&""""
' item&"="&tempvalue&"<br/>"
next
' request("id")
'
if ="" then
"<script language='JavaScript'>('')</script>"
"<script language='JavaScript'>(-1);</script>"
end if
<!--#include file="" -->
<!--#include virtual="" -->
sql="select max(id) from pack"
set RS=(sql)
if isnull(RS(0)) then
id=1
else
id=RS(0)+1
end if
set rs=nothing
sql="insert into pack(id,strpackdm,strusername) values("&id&",'"&strpackdm&"','"&Session("username")&"')"
set RS=(sql)
sql="update pack set "&Itemname&"='"&tempvalue&"' where "
if Itemname<>"id" then
sql&"<br/>"
set rs=(sql)
if <>0 then
'Error handling
"Database operation failed:" &
end if
Set rs=Nothing
Set conn=Nothing
do while not and rowcount>0
rowcount=rowcount-1
do while not
loop
for each item in
Execute &"="""&trim(rs2(""&&""))&""""
next
function Mycn(str)
str=lcase(str)
str=replace(str,"","")
str
end function
dim conn
dim connstr
on error resume next
set conn=("")
Connstr="driver=SQL Server; server="&servername&"; u; pwd="&password&"; database="&datebasename&";"
Connstr="DBQ="+(mydbpath&mdbname)+";DRIVER={Microsoft Access Driver (*.mdb)};"
' Connstr
'
connstr
if err<>0 then
"Cannot establish a connection to the database!"
end if
ASP implementation example of MD5 irreversible encryption algorithm (I)
This is a foreign reprint function, which can convert any character to md5 16 as a character encryption form, and it is irreversible.
<%
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32
Private m_lOnBits(30)
Private m_l2Power(30)
Private Function LShift(lValue, iShiftBits)
If iShiftBits = 0 Then
LShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And 1 Then
LShift = &H80000000
Else
LShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
6
End If
If (lValue And m_l2Power(31 - iShiftBits)) Then
LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
Else
LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
End If
End Function
Private Function RShift(lValue, iShiftBits)
If iShiftBits = 0 Then
RShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And &H80000000 Then
RShift = 1
Else
RShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
6
End If
RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
If (lValue And &H80000000) Then
RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
End If
End Function
Private Function RotateLeft(lValue, iShiftBits)
RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
End Function
Private Function AddUnsigned(lX, lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult
lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000
lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If
AddUnsigned = lResult
End Function
Private Function md5_F(x, y, z)
md5_F = (x And y) Or ((Not x) And z)
End Function
Private Function md5_G(x, y, z)
md5_G = (x And z) Or (y And (Not z))
End Function
Private Function md5_H(x, y, z)
md5_H = (x Xor y Xor z)
End Function
Private Function md5_I(x, y, z)
md5_I = (y Xor (x Or (Not z)))
End Function
Private Sub md5_FF(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_F(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a,
End Sub
Private Sub md5_GG(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_G(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a,
End Sub
Private Sub md5_HH(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_H(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a,
End Sub
Private Sub md5_II(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_I(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a,
End Sub
Private Function ConvertToWordArray(sMessage)
Dim lMessageLength
Dim lNumberOfWords
Dim lWordArray()
Dim lBytePosition
Dim lByteCount
Dim lWordCount
Const MODULUS_BITS = 512
Const CONGRUENT_BITS = 448
lMessageLength = Len(sMessage)
lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
ReDim lWordArray(lNumberOfWords - 1)
lBytePosition = 0
lByteCount = 0
Do Until lByteCount >= lMessageLength
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)
lByteCount = lByteCount + 1
Loop
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)
lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
ConvertToWordArray = lWordArray
End Function
Private Function WordToHex(lValue)
Dim lByte
Dim lCount
For lCount = 0 To 3
lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
Next
End Function
ASP implementation example of MD5 irreversible encryption algorithm (I)
--------------------------------------
Public Function MD5(sMessage)
m_lOnBits(0) = CLng(1)
m_lOnBits(1) = CLng(3)
m_lOnBits(2) = CLng(7)
m_lOnBits(3) = CLng(15)
m_lOnBits(4) = CLng(31)
m_lOnBits(5) = CLng(63)
m_lOnBits(6) = CLng(127)
m_lOnBits(7) = CLng(255)
m_lOnBits(8) = CLng(511)
m_lOnBits(9) = CLng(1023)
m_lOnBits(10) = CLng(2047)
m_lOnBits(11) = CLng(4095)
m_lOnBits(12) = CLng(8191)
m_lOnBits(13) = CLng(16383)
m_lOnBits(14) = CLng(32767)
m_lOnBits(15) = CLng(65535)
m_lOnBits(16) = CLng(131071)
m_lOnBits(17) = CLng(262143)
m_lOnBits(18) = CLng(524287)
m_lOnBits(19) = CLng(1048575)
m_lOnBits(20) = CLng(2097151)
m_lOnBits(21) = CLng(4194303)
m_lOnBits(22) = CLng(8388607)
m_lOnBits(23) = CLng(16777215)
m_lOnBits(24) = CLng(33554431)
m_lOnBits(25) = CLng(67108863)
m_lOnBits(26) = CLng(134217727)
m_lOnBits(27) = CLng(268435455)
m_lOnBits(28) = CLng(536870911)
m_lOnBits(29) = CLng(1073741823)
m_lOnBits(30) = CLng(2147483647)
m_l2Power(0) = CLng(1)
m_l2Power(1) = CLng(2)
m_l2Power(2) = CLng(4)
m_l2Power(3) = CLng(8)
m_l2Power(4) = CLng(16)
m_l2Power(5) = CLng(32)
m_l2Power(6) = CLng(64)
m_l2Power(7) = CLng(128)
m_l2Power(8) = CLng(256)
m_l2Power(9) = CLng(512)
m_l2Power(10) = CLng(1024)
m_l2Power(11) = CLng(2048)
m_l2Power(12) = CLng(4096)
m_l2Power(13) = CLng(8192)
m_l2Power(14) = CLng(16384)
m_l2Power(15) = CLng(32768)
m_l2Power(16) = CLng(65536)
m_l2Power(17) = CLng(131072)
m_l2Power(18) = CLng(262144)
m_l2Power(19) = CLng(524288)
m_l2Power(20) = CLng(1048576)
m_l2Power(21) = CLng(2097152)
m_l2Power(22) = CLng(4194304)
m_l2Power(23) = CLng(8388608)
m_l2Power(24) = CLng(16777216)
m_l2Power(25) = CLng(33554432)
m_l2Power(26) = CLng(67108864)
m_l2Power(27) = CLng(134217728)
m_l2Power(28) = CLng(268435456)
m_l2Power(29) = CLng(536870912)
m_l2Power(30) = CLng(1073741824)
Dim x
Dim k
Dim AA
Dim BB
Dim CC
Dim DD
Dim a
Dim b
Dim c
Dim d
Const S11 = 7
Const S12 = 12
Const S13 = 17
Const S14 = 22
Const S21 = 5
Const S22 = 9
Const S23 = 14
Const S24 = 20
Const S31 = 4
Const S32 = 11
Const S33 = 16
Const S34 = 23
Const S41 = 6
Const S42 = 10
Const S43 = 15
Const S44 = 21
x = ConvertToWordArray(sMessage)
a = &H67452301
b = &HEFCDAB89
c = &H98BADCFE
d = &H10325476
F
Previous page12Read the full text