이 모듈에서는 ASP(Active Server Pages)에서 세션 정보를 유지하는 과정을 설명합니다. 세션은 특정 사용자가 웹 사이트 내용을 활성화시켜서 보고 있는 타임 세그먼트를 참조합니다. 세션은 사용자가 사이트의 첫 페이지를 방문할 때 시작하여, 사이트를 떠난 지 몇 분 후에 끝납니다. 특정 세션에 대한 사용자별 정보를 통칭하여 세션 정보라고 합니다.
HTTP는 상태 비저장 프로토콜이기 때문에 웹 사이트를 방문하는 사용자에 대한 상태를 유지하려고 하면 문제가 발생합니다. 웹 서버는 각 HTTP 요청을 이전 요청과 관계 없는 고유한 요청으로 처리합니다. 따라서 사용자가 폼 등을 통해 페이지에서 입력한 정보가 다음 페이지에 자동으로 표시되지는 않습니다. 웹 서버는 세션 정보를 유지하여 사용자가 웹 사이트를 탐색할 때 사용자를 식별하고 추적해야 합니다.
쿠키를 사용하여 문제를 해결할 수 있습니다. 쿠키는 페이지에서 사용자에 대한 정보를 기록하여 사이트 내의 다른 페이지로 전송합니다. 쿠키를 인식하지 못하는 일부 브라우저에서는 사용자가 쿠키 사용을 해제할 수 있습니다. HTTP POST를 사용하면 쿠키를 사용하지 않고도 세션 정보를 유지하여 웹 사용자들을 관리할 수 있습니다.
이 모듈은 다음 내용으로 구성되어 있습니다.
쿠키는 신용 카드 번호나 암호 등의 사용자별 정보 집합을 저장합니다. 웹 서버는 사이트의 다른 페이지에서도 사용자 정보를 사용할 수 있도록 쿠키를 사용자의 웹 서버에 포함시킵니다. 사용자는 방문하는 모든 페이지에서 자신의 정보를 다시 입력할 필요가 없습니다. 쿠키는 웹 기반 쇼핑에서 또는 웹 사용자의 개인 기본 설정을 유지하거나 사용자에 대한 정보를 유지하기 위해 고객 정보를 수집하는 좋은 방법입니다.
다음 두 종류의 쿠키가 있습니다.
만료 날짜를 지정하지 않고 만드는 쿠키는 브라우저 해당 세션에서만 존재하는 메모리 내 쿠키입니다. 다음은 메모리 내 쿠키에 사용하는 스크립트입니다.
Response.Cookies("SiteArea") = "TechNet"
세션과 상관 없이 쿠키 정보를 유지하려면 만료 날짜를 지정하여 영구적 쿠키를 만들어야 합니다. 만료 날짜를 지정하면 브라우저가 클라이언트 컴퓨터에 쿠키를 저장합니다. 영구적 쿠키의 데이터는 만료 날짜에 도달할 때까지 클라이언트 컴퓨터에 상주합니다. 원래의 웹 사이트를 요청하면 사이트에서 만든 쿠키를 자동으로 연결합니다. 웹 사이트 이름과 ASP 파일의 일부가 쿠키에 있는 데이터를 구성하기 때문에 쿠키는 쿠키를 만든 사이트에만 연결됩니다.
다음은 영구적 쿠키를 만드는 데 사용하는 스크립트입니다.
Response.Cookies("SiteArea") = "TechNet"
Response.Cookies("SiteArea").Expires = "August 15, 2000"
쿠키는 HTML 텍스트를 브라우저로 보내기 전에 생성되어야 하기 때문에, ASP 파일 처음에 배치해야 합니다.
Response와 Request 개체는 메모리 내 쿠키를 만들 때도 사용하지만 이 쿠키를 사용하여 영구적 쿠키를 만들 수도 있습니다. 대부분의 웹 응용 프로그램은 이러한 개체를 사용하여 세션 정보를 유지합니다.
이 단원에서는 Response 개체와 Request 개체를 사용하여 다음과 같은 파일을 만듭니다. 다른 파일을 필요로 하는 파일도 있으므로 파일을 한꺼번에 만드십시오. 파일을 모두 만들고 브라우저에서 http://LocalHost/Tutorial/Frame.htm을 입력하여 응용 프로그램을 실행합니다.
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 C:\Inetpub\Wwwroot\Tutorial\Frame.htm으로 저장합니다.
<html>
<head>
<title>Customized Greeting and Colors Using In-Memory and Persistent Cookies</title>
</head>
<frameset cols="40%,60%">
<frame src="menu.htm" name="left" marginheight="5" marginwidth="5">
<frame src="CustomGreeting.asp" name="right" marginheight="5" marginwidth="5">
</frameset>
<noframes>
Sorry, your browser does not support frames. Please go to the <a href="menu.htm">Menu</a>.
</noframes>
</html>
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 C:\Inetpub\Wwwroot\Tutorial\Menu.htm으로 저장합니다.
<html>
<head>
<title>Maintaining Session State With Cookies</title>
</head>
<body>
<font face="MS Gothic">
<h2 align="center">Cookie Examples</h2>
<table align=center border=1 cellpadding=4>
<tr>
<td><a href="CustomGreeting.asp" target="right"><b>Custom Greeting Page</b></a></td>
</tr><tr>
<td><a href="DeleteGreetingCookie.asp" target="right"><b>Delete the Greetings Cookie</b></a></td>
</tr><tr>
<td><a href="SelectColors.asp" target="right"><b>Set Page Colors</b></a></td>
</tr><tr>
<td><a href="DeleteColorCookie.asp" target="right"><b>Delete Page Colors Cookies</b></a></td>
</tr><tr>
<td><a href="Cookie.asp" target="right"><b>Set Cookies for Date, Time and Total Visits</b></a></td>
</tr><tr>
<td><a href="DeleteCookies.asp" target="right"><b>Delete Cookies for Date, Time and Total Visits</b></a></td>
</tr>
</table>
</font>
</body>
</html>
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 C:\Inetpub\Wwwroot\Tutorial\CustomGreeting.asp로 저장합니다.
<%@ Language="VBScript" %>
<%
'If the user has selected text and background colors,
' cookies are used to remember the values between HTTP sessions.
'Do this first so that your page can use use the values if they are set.
If Not (Request.QueryString("Text")="") Then
Response.Cookies("TextColor") = Request.QueryString("Text")
Response.Cookies("BackgroundColor") = Request.QueryString("Background")
End If
' If the user has typed in a name, a cookie is created.
If Not (Request.QueryString("Name")="") Then
Response.Cookies ("Name") = Request.QueryString("Name")
' If the user does not give his/her name, a cookie
' is created so that we do not keep asking for the name.
ElseIf (InStr(Request.QueryString,"Name")=1) Then
Response.Cookies ("NoUserInput") = "TRUE"
End If
%>
<html>
<head>
</head>
<%
'Set colors according to existing previous user input.
If (Request.Cookies ("TextColor")="") Then %>
<body>
<% Else %>
<body bgcolor=<%=Request.Cookies("BackgroundColor")%> text=<%=Request.Cookies("TextColor")%>>
<% End If
%>
<font face="MS Gothic">
<%
'If there is no name cookie set, no name entered by the user,
' and there was no user input at all, get the user's name.
If ( (Request.Cookies("Name")="") And ((Request.QueryString("Name"))="")) And (Not(Request.Cookies("NoUserInput")="TRUE") ) Then %>
<FORM ACTION="CustomGreeting.asp" METHOD="GET" NAME="DataForm">
<table align=center><tr><td>
<INPUT TYPE=TEXTBOX NAME="Name" SIZE=33></td></tr><tr><td>
<INPUT TYPE=Submit VALUE="Please Enter Your Name"></td></tr></table>
</FORM>
<% ElseIf Not(Request.Cookies("Name")="") Then %>
<H2 align=center>Greetings <%=Request.Cookies("Name")%></H2>
<% Else %>
<H2>Hello!</H2>
<H3>You did not give us your name so we are not able to greet you by name.</H3>
<% End If
%>
<H3>In-Memory Cookie Example</H3>
<P>
Once you enter your name:
<UL>
<LI>If you hit <B>Refresh</B> in your browser, you should still see your name.</LI>
<LI>If you close your browser, the cookie is deleted. When you re-open your browser to this page, you should be asked for your name again.</LI>
<LI>If you click on <B>Delete the Greetings Cookie</B>, and click on <B>Custom Greeting Page</B>, you should be asked for your name again.</LI>
</P>
</font>
</body>
</html>
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 C:\Inetpub\Wwwroot\Tutorial\DeleteGreetingCookie.asp로 저장합니다.
<%@ Language="VBScript" %>
<html>
<head>
</head>
<% If (Request.Cookies ("TextColor")="") Then %>
<body>
<font face="MS Gothic">
<% Else %>
<body bgcolor=<%=Request.Cookies("BackgroundColor")%> text=<%=Request.Cookies("TextColor")%>>
<font face="MS Gothic" color=<%=Request.Cookies("TextColor")%>>
<% End If %>
<%
If Not ("" = Request.Cookies("Name")) Then
Response.Cookies ("Name").Expires = "January 1, 1992"
Response.Cookies ("NoUserInput").Expires = "January 1, 1992" %>
<h2 align=center>In-Memory Greeting Cookie Deleted</h2>
<P>
The cookie used to keep track of your name has been deleted.<BR>
Please click on <B>Custom Greeting Page</B> to be asked for your name again.
</P>
<% Else %>
<h2 align=center>No In-Memory Greeting Cookie Deleted</h2>
<P>
There was no cookie set with your name.<BR>
Please click on <B>Custom Greeting Page</B> to enter your name.
</P>
<% End If
%>
</font>
</body>
</html>
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 C:\Inetpub\Wwwroot\Tutorial\SelectColors.asp로 저장합니다.
<%@ Language="VBScript" %>
<%
' If the user has selected text and background colors,
' cookies are used to remember the values between HTTP sessions.
If Not (Request.QueryString("Text")="") Then
Response.Cookies ("TextColor") = Request.QueryString("Text")
Response.Cookies ("BackgroundColor") = Request.QueryString("Background")
End If
%>
<html>
<head>
</head>
<%
'Set colors according to existing previous user input.
If (Request.Cookies ("TextColor")="") Then %>
<body>
<% Else %>
<body bgcolor=<%=Request.Cookies("BackgroundColor")%> text=<%=Request.Cookies("TextColor")%>>
<% End If
%>
<font face="MS Gothic">
<H2 align=center>Select the colors for your Web page</H2>
<P>
In Memory Cookies will be used to store these values.
</P>
<FORM ACTION="SelectColors.asp" METHOD="GET" NAME="DataForm">
<table border="1" width="450" cellpadding=0>
<tr><td>
<table>
<tr><td BGCOLOR=99FF99>
<B><font color=000000>Please select the background color</font></B>
</td></tr><tr><td BGCOLOR=FFFFFF>
<input type="RADIO" NAME="Background" VALUE="FFFFFF" CHECKED><font COLOR=000000> FFFFFF </font>
</td></tr><tr><td BGCOLOR=D98719>
<input type="RADIO" NAME="Background" VALUE="D98719"> D98719
</td></tr><tr><td BGCOLOR=D9D919>
<input type="RADIO" NAME="Background" VALUE="D9D919"> D9D919
</td></tr><tr><td BGCOLOR=00FFFF>
<input type="RADIO" NAME="Background" VALUE="00FFFF"> 00FFFF
</td></tr><tr><td BGCOLOR=FF00FF>
<input type="RADIO" NAME="Background" VALUE="FF00FF"> FF00FF
</td></tr><tr><td BGCOLOR=000000>
<input type="RADIO" NAME="Background" VALUE="000000"> <font COLOR=FFFFFF>000000</font>
</td></tr>
</table>
</td><td>
<table>
<tr><td BGCOLOR=99FF99>
<B><font color=000000>Please select the text color</font></B>
</td></tr><tr><td BGCOLOR=FFFFFF>
<input type="RADIO" NAME="Text" VALUE="FFFFFF" CHECKED><font COLOR=000000> FFFFFF </font>
</td></tr><tr><td BGCOLOR=D98719>
<input type="RADIO" NAME="Text" VALUE="D98719"> D98719
</td></tr><tr><td BGCOLOR=D9D919>
<input type="RADIO" NAME="Text" VALUE="D9D919"> D9D919
</td></tr><tr><td BGCOLOR=00FFFF>
<input type="RADIO" NAME="Text" VALUE="00FFFF"> 00FFFF
</td></tr><tr><td BGCOLOR=FF00FF>
<input type="RADIO" NAME="Text" VALUE="FF00FF"> FF00FF
</td></tr><tr><td BGCOLOR=000000>
<input type="RADIO" NAME="Text" VALUE="000000" CHECKED><font COLOR=FFFFFF> 000000 </font>
</td></tr>
</table>
</td></tr>
</table>
<P>
<input type=Submit VALUE="Submit selected colors">
</FORM>
</font>
</body>
</html>
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 C:\Inetpub\Wwwroot\Tutorial\DeleteColorCookie.asp로 저장합니다.
<%@ Language="VBScript" %>
<html>
<head>
</head>
<body>
<font face="MS Gothic">
<%
If Not ("" = Request.Cookies("TextColor")) Then
Response.Cookies("TextColor").Expires = "January 1, 1992"
Response.Cookies("BackgroundColor").Expires = "January 1, 1992" %>
<h2 align=center>In-Memory Color Cookie Deleted</h2>
<P>
The cookie used to keep track of your display colors has been deleted.<BR>
Please click on <B>Set Page Colors</B> to set your colors again.
</P>
<% Else %>
<h2 align=center>No In-Memory Color Cookie Deleted</h2>
<P>
There was no cookie set with your color choices.<BR>
Please click on <B>Set Page Colors</B> to set display colors.
</P>
<% End If
%>
</font>
</body>
</html>
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 C:\Inetpub\Wwwroot\Tutorial\Cookie.asp로 저장합니다.
<%@ Language="VBScript" %>
<%
LastAccessTime = Request.Cookies("LastTime")
LastAccessDate = Request.Cookies("LastDate")
'If the NumVisits cookie is empty, set to 0, else increment it.
If (Request.Cookies("NumVisits")="") Then
Response.Cookies("NumVisits") = 0
Else
Response.Cookies("NumVisits") = Request.Cookies("NumVisits") + 1
End If
Response.Cookies("LastDate") = Date
Response.Cookies("LastTime") = Time
'Setting an expired date past the present date creates a persistent cookie.
Response.Cookies("LastDate").Expires = "January 15, 2001"
Response.Cookies("LastTime").Expires = "January 15, 2001"
Response.Cookies("NumVisits").Expires = "January 15, 2001"
%>
<html>
<head>
</head>
<% If (Request.Cookies ("TextColor")="") Then %>
<body>
<font face="MS Gothic">
<% Else %>
<body bgcolor=<%=Request.Cookies("BackgroundColor")%> text=<%=Request.Cookies("TextColor")%>>
<font face="MS Gothic" color=<%=Request.Cookies("TextColor")%>>
<% End If %>
<H2 align=center>Persistent Client-Side Cookies!</H2>
<P>
Three persistent client-side cookies are created.
< UL>
<LI>A cookie to count the number of times you visited the Web page.</LI>
<LI>A cookie to determine the date of your visit.</LI>
<LI> A cookie to determine the time of your visit.</LI>
</UL>
</P>
<table border="1" width="300" cellpadding=4 align=center>
<tr><td>
<% If (Request.Cookies ("NumVisits")=0) Then %>
Welcome! This is your first visit to this Web site!
<% Else %>
Thank you for visiting again! You have been to this Web page a total of <B><%=Request.Cookies("NumVisits")%></B> time(s).
<% End If %>
</td></tr>
</table>
<P>
<B>The Current time is <%=Time%> on <%=Date%><BR>
<% If (Request.Cookies ("NumVisits")>0) Then %>
You last visited this Web page at <%=LastAccessTime%> on <%=LastAccessDate%>
<% End If %>
</strong>
</P>
</font>
</body>
</html>
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 DeleteCookies.asp로 저장합니다.
<%@ Language="VBScript" %>
<html>
<head>
</head>
<% If (Request.Cookies ("TextColor")="") Then %>
<body>
<font face="MS Gothic">
<% Else %>
<body bgcolor=<%=Request.Cookies("BackgroundColor")%> text=<%=Request.Cookies("TextColor")%>>
<font face="MS Gothic" color=<%=Request.Cookies("TextColor")%>>
<% End If %>
<%
If Not ("" = Request.Cookies("NumVisits")) Then
Response.Cookies("NumVisits").Expires = "January 1, 1993"
Response.Cookies("LastDate").Expires = "January 1, 1993"
Response.Cookies("LastTime").Expires = "January 1, 1993" %>
<H2 align=center>Persistent Cookies Are Deleted</H2>
<P>
The cookies used to keep track of your visits and date and time of last visit have been deleted.<BR>
Please click on <B>Set Cookies for Date, Time and Total Visits</B> to set your cookies again.
</P>
<% Else %>
<H2 align=center>No Persistent Cookies Are Deleted</H2>
<P>
There were no cookies set to keep track of your visits, and date and time of last visit.<BR>
Please click on <B>Set Cookies for Date, Time and Total Visits</B> to set your colors again.
</P>
<% End If %>
</font>
</body>
</html>
Session 개체를 사용하여 메모리 내 쿠키만 만들 수 있습니다. Session 개체가 올바르게 작동하기 위해서는 사용자가 사이트를 방문한 시간과 떠난 시간을 알아야 합니다. IIS에서는 사용자에 대한 정보 집합을 유지하기 위해 사용하는 ASP 세션 ID가 저장된 쿠키를 사용하여 이러한 시간을 결정합니다. ASP 세션 ID가 없는 경우 서버는 현재 요청을 방문 시작으로 간주합니다. 기본 시간 간격인 20분 동안 사용자가 ASP 파일을 요청하지 않으면 방문이 끝납니다.
이 단원에서 다음을 만들 수 있습니다.
응용 프로그램이나 세션을 시작하거나 끝내는 것을 이벤트라고 합니다. Global.asa 파일을 사용하여 이벤트에 응답하여 실행되도록 미리 정의된 이벤트를 사용할 수 있습니다.
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 루트 디렉터리에 파일을 C:\Inetpub\Wwwroot\Global.asa로 저장합니다.
중요: Global.asa 파일을 ASP 응용 프로그램의 루트 디렉터리에 저장하여 해당 응용 프로그램을 찾아야 합니다. C:\Inetpub\Wwwroot\Test로 매핑된 가상 경로 Test가 있는 경우 URL은 http://LocalHost/Test이고 Global.asa 파일은 C:\Inetpub\Wwwroot\Test에 있어야 합니다. C:\Inetpub\Wwwroot\Tutorial로 매핑되는 가상 경로를 이미 만들었기 때문에 루트 디렉터리는 C:\Inetpub\Wwwroot입니다.
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
'Using application-level variables to track the number of users
' that are currently looking at the site and the number that have
' accessed the site.
Sub Application_OnStart
'Get the physical path to this vdir, and append a filename.
Application("PhysPath") = Server.MapPath(".") & "\hits.txt"
'Set some Visual Basic constants, and instantiate the FileSystemObject object.
Const cForReading = 1
Const cTristateUseDefault = -2
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
'Get the last saved value of page hits and the date that it happened.
If fsoObject.FileExists(Application("PhysPath")) Then
'If the file hits.txt exists, set the Application variables.
Set tsObject = fsoObject.OpenTextFile(Application("PhysPath"), cForReading, cTristateUseDefault)
Application("HitCounter") = tsObject.ReadLine
Application("AppStartDate") = tsObject.ReadLine
tsObject.Close
Else 'No file has been saved, so reset the values.
Application("HitCounter") = 0
Application("AppStartDate") = Date
End If
Application("CurrentUsers") = 0
End Sub
Sub Application_OnEnd
Const cForWriting = 2
Const cTristateUseDefault = -2
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
If fsoObject.FileExists(Application("PhysPath")) Then
'If the file exists, open it for writing.
set tsObject = fsoObject.OpenTextFile(Application("PhysPath"), cForWriting, cTristateUseDefault)
Else
'If the file doesn't exist, create a new one.
set tsObject = fsoObject.CreateTextFile(Application("PhysPath"))
End If
'Write the total number of site hits and the last day recorded to the file.
tsObject.WriteLine(Application("HitCounter"))
tsObject.WriteLine(Application("AppStartDate"))
tsObject.Close
End Sub
Sub Session_OnStart
'The Session time-out default is changed to 1 for the purposes of
' this example.
Session.Timeout = 1
'When you change Application variables, you must lock them so that other
' sessions cannot change them at the same time.
Application.Lock
'Increment the site hit counter.
Application("HitCounter") = Application("HitCounter") + 1
Application("CurrentUsers") = Application("CurrentUsers") + 1
Application.UnLock
End Sub
Sub Session_OnEnd
Application.Lock
'Decrement the current user counter.
Application("CurrentUsers") = Application("CurrentUsers") - 1
Application.UnLock
End Sub
</SCRIPT>
Global.asa에서 변수 집합을 사용하여 방문과 세션을 측정할 수 있습니다.
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 C:\Inetpub\Wwwroot\Tutorial\VisitCount.asp로 저장합니다. http://Localhost/Tutorial/VisitCount.asp를 입력하여 브라우저에서 파일을 봅니다.
http://Localhost/Tutorial/VisitCount.asp에 대한 브라우저의 두 번째 인스턴스를 열고 첫 번째 브라우저에서 새로 고침을 클릭합니다. 총 방문자 수와 현재 방문자 수는 한 명씩 증가해야 합니다. 두 번째 브라우저를 닫고 잠시 기다린 후 첫 번째 브라우저에서 새로 고침을 클릭합니다. 현재 방문자는 한 명씩 감소해야 합니다.
<% Response.Buffer = True%>
<html>
<head>
<title>Retrieving Variables Set in Global.asa</title>
</head>
<body>
<font face="MS Gothic">
<H3 align=center>Retrieving Variables Set in Global.asa</H3>
<P>
Total Visitors = <%=Application("HitCounter")%> since <%=Application("AppStartDate")%><BR>
Active Visitors = <%=Application("CurrentUsers")%>
</P>
</font>
</body>
</html>
쿠키를 인식하지 못하는 일부 브라우저에서는 사용자가 쿠키 사용을 해제할 수 있습니다. HTTP POST 메서드를 사용하면 쿠키를 사용하지 않고도 세션 정보를 유지할 수 있습니다. HTTP POST 메서드가 제공하는 상태 정보는 쿠키와 동일하지만 쿠키를 사용할 수 없는 경우에도 작동한다는 이점이 있습니다. 실제로 이 메서드를 많이 사용하지는 않지만 배워 보는 것이 좋습니다. HTTP POST 메서드는 메모리 내 쿠키와 유사하게 작동하며 방문하는 동안에만 사용자 정보가 유지되고 사용자가 브라우저를 종료하면 세션 정보도 사라집니다.
텍스트 편집기에서 새 파일을 열어 다음 스크립트에 붙여넣고 파일을 C:\Inetpub\Wwwroot\Tutorial\DataEntry.asp로 저장합니다. http://Localhost/Tutorial/DataEntry.asp를 입력하여 브라우저에서 파일을 봅니다.
<%@ Language=VBScript %>
<html>
<head>
<title>Data Entry Without Cookies</title>
</head>
<body>
<font face="MS Gothic">
<!-- In this example, subroutines are listed first.
There's a subroutine for each page of the order process.
The main calling code is at the bottom. -->
<% Sub DisplayInitialPage %>
<table border=1 cellpadding=3 cellspacing=0 width=500 bordercolor=#808080 align=center>
<tr><td bgColor=#004080 align=center>
<font color=#ffffff><H2>Order Form</H2></font>
</td></tr><tr><td bgColor=#e1e1e1 align=left>
<P><B>Step 1 of 4</B></P>
<P align=center>
This form uses the HTTP POST method to pass along hidden values that contain
your order information. This form does not use cookies.
</P>
<FORM METHOD=POST ACTION="DataEntry.asp" NAME=DataEntryForm>
<P>Enter your name
<INPUT TYPE="TEXT" NAME=FullName>
<BR>Enter your imaginary credit card number
<INPUT TYPE="TEXT" NAME=CreditCard>
</P>
<!-- Keeps track of the information by using the hidden HTML form variable Next Page. -->
<INPUT TYPE="HIDDEN" NAME=NextPage VALUE=2>
<INPUT TYPE="SUBMIT" VALUE="Next ->" NAME=NextButton>
</FORM>
</td></tr>
</table>
<% End Sub %>
<% Sub DisplayDogBreed %>
<table border=1 cellpadding=3 cellspacing=0 width=500 align=center>
<tr><td bgColor=#004080 align=center>
<font color=#ffffff><H2>Order Form</H2></font>
</td></tr><tr><td bgColor=#e1e1e1>
<P><B>Step 2 of 4</B></P>
<P align=center>
Please select the type of dog you want.
</P>
<FORM METHOD=POST ACTION="DataEntry.asp" NAME=DataEntryForm>
<P>
<INPUT TYPE=RADIO NAME=DogSelected VALUE="Cocker Spaniel" CHECKED>Cocker Spaniel<BR>
<INPUT TYPE=RADIO NAME=DogSelected VALUE="Doberman">Doberman<BR>
<INPUT TYPE=RADIO NAME=DogSelected VALUE="Timber Wolf">Timber Wolf<BR>
<INPUT TYPE=RADIO NAME=DogSelected VALUE="Mastiff">Mastiff<BR>
</P>
<!--Keeps track of the information by using the hidden HTML form variable Next Page. -->
<INPUT TYPE="HIDDEN" NAME=NextPage VALUE=3>
<INPUT TYPE="SUBMIT" VALUE="Next ->" NAME=NextButton>
</FORM>
</td></tr>
</table>
<% End Sub %>
<% Sub DisplayCity %>
<table border=1 cellpadding=3 cellspacing=0 width=500 align=center>
<tr><td bgColor=#004080 align=center>
<font color=#ffffff><H2>Order Form</H2></font>
</td></tr><tr><td bgColor=#e1e1e1>
<P><B>Step 3 of 4</B></P>
<P align=center>
We deliver from the following cities. Please choose the one closest to you.
</P>
<FORM METHOD=POST ACTION="DataEntry.asp" NAME=DataEntryForm>
<P>
<INPUT TYPE=RADIO NAME=CitySelected VALUE="Seattle" CHECKED>Seattle<BR>
<INPUT TYPE=RADIO NAME=CitySelected VALUE="Los Angeles">Los Angeles<BR>
<INPUT TYPE=RADIO NAME=CitySelected VALUE="Boston">Boston<BR>
<INPUT TYPE=RADIO NAME=CitySelected VALUE="New York">New York<BR>
</P>
<!--Keeps track of the information by using the hidden HTML form variable Next Page. -->
<INPUT TYPE="HIDDEN" NAME=NextPage VALUE=4>
<INPUT TYPE="SUBMIT" VALUE="Next ->" NAME=NextButton>
</FORM>
</td></tr>
</table>
<% End Sub %>
<% Sub DisplaySummary %>
<table border=1 cellpadding=3 cellspacing=0 width=500 align=center>
<tr><td bgColor=#004080 align=center>
<font color=#ffffff><H2>Order Form Completed</H2></font>
</td></tr><tr><td bgColor=#e1e1e1>
<P><B>Step 4 of 4</B></P>
<P align=center>
The following information was entered.<BR>
A transaction will now be executed to complete your order if your name and
credit card are valid.
</P>
<table cellpadding=4>
<tr bgcolor=#ffffcc><td>
Name
</td><td>
<%=Session.Value("FullName")%>
</td></tr><tr bgcolor=Beige><td>
Credit Card
</td><td>
<%=Session.Value("CreditCard")%>
</td></tr><tr bgcolor=Beige><td>
Dog Ordered
</td><td>
<%=Session.Value("DogSelected")%>
</td></tr><tr bgcolor=Beige><td>
City Ordered From
</td><td>
<%=Session.Value("CitySelected")%>
</td></tr>
</table>
</td>
</tr>
</table>
<% End Sub %>
<% Sub StoreUserDataInSessionObject %>
<%
Dim FormKey
For Each FormKey in Request.Form
Session(FormKey) = Request.Form.Item(FormKey)
Next
%>
<% End Sub %>
<%
'This is the main code that calls all the subroutines depending on the
' hidden form elements.
Dim CurrentPage
If Request.Form.Item("NextPage") = "" Then
CurrentPage = 1
Else
CurrentPage = Request.Form.Item("NextPage")
End If
'Save all user data so far.
Call StoreUserDataInSessionObject
Select Case CurrentPage
Case 1 : Call DisplayInitialPage
Case 2 : Call DisplayDogBreed
Case 3 : Call DisplayCity
Case 4 : Call DisplaySummary
End Select %>
<BR>
<HR>
<H3 align=center><A HREF="DataEntry.asp">Reset Order</A></H3>
</font>
</body>
</html>