Presentation on theme: "Session Variables Storing Session Variables on the Server."— Presentation transcript:
Session Variables Storing Session Variables on the Server
What Is a Session? When a browser hits a site, the server begins a new Session. Automatically, a unique Session ID is assigned and the browser owns that session. The session lasts until the browser closes. During the life of the session, scripts can store data in it.
What Is a Session Variable? A session variable is a memory location on the Server that can hold a value for the duration of the session. In ASP, you set a session variable via the command: Replace varName by the actual name of your variable, and replace value by what you want to store there.
Getting Form Data into Session Variables You can store in Session variables data obtained from the user via forms. The data persists in the Session variables until the browser closes. The syntax is: Replace varName by the name of your variable, and replace inputName by the name of the form field.
Working Through an Example The best way to understand session variables is to work through an example containing three Web pages that you will create: First, create a form that prompts the user to enter something. Second, create an ASP page that receives the entry and puts it into a Session variable. Third, create an ASP page that displays the Session variable.
Creating the Form (page 2 of 3) In front of the text field, prompt the user to type something, such as their name:
Creating the Form (page 3 of 3) Make the name of the text field be: namefield Make the form’s action be: SessionVariableSet.asp Save the page containing the form. Read on to create the page that will handle the form.
Testing the Example Publish the following pages to your remote site: SessionVariablePrompt.asp SessionVariableSet.asp SessionVariableDisplay.asp Browse to SessionVariablePrompt.asp at your remote site. Fill out the form, click Submit, and follow the link to the session variable display page. If the username fails to display, troubleshoot any problems until you get this to work.