Presentation is loading. Please wait.

Presentation is loading. Please wait.

Session Variables Storing Session Variables on the Server.

Similar presentations


Presentation on theme: "Session Variables Storing Session Variables on the Server."— Presentation transcript:

1 Session Variables Storing Session Variables on the Server

2 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.

3 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.

4 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.

5 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.

6 Creating the Form (page 1 of 3) Use Dreamweaver to create a new ASP Javascript page. Save the page as SessionVariablePrompt.asp. Use the Forms menu to put a form on the page. Inside the form, create a text input field and a submit button.

7 Creating the Form (page 2 of 3) In front of the text field, prompt the user to type something, such as their name:

8 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.

9 Creating the Handler Use Dreamweaver to create a new ASP Javascript page. Save the page as SessionVariableSet.asp. In code view, make the body of the page read as follows: The session variable has been created. To see its value, go to the session variable display page. Save the page.

10 Creating the Displayer Use Dreamweaver to create a new ASP Javascript page. Save the page as SessionVariableDisplay.asp. In code view, make the body of the page read as follows: The value of the session variable named "username" is: Save the page.

11 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.

12 Sample Test Run


Download ppt "Session Variables Storing Session Variables on the Server."

Similar presentations


Ads by Google