Home > Products > UltraDev > Support > Building Common Applications
Dreamweaver UltraDev Icon Macromedia Dreamweaver UltraDev Support Center - Building Common Applications
What session variables can do for you

A Web server doesn't keep track of page requests from users. Every time a Web server sends a page to a user's browser, it "forgets" it. When the same user requests a related page later, the server sends the page without knowing the last page sent to the user.

This presents a problem if you want a page to behave a certain way based on a choice the user made on a previous page, or if you want to remember information from one page to the next—in computer programming terms, if you want to maintain state in the Web application.

One way to maintain state is to use session variables. Session variables store information for the life of the user's session. The user's session begins when he or she first opens a page within the application. The session ends when the user does not open another page in the application for a certain period of time, or when the user explicitly terminates the session (typically by clicking a log-off link). While it exists, the session is specific to an individual user, and every user has a separate session.

You can use session variables to store information that every page in your Web application can access. The information can be as diverse as the user's name, preferred font size (if the site caters to the elderly, for example), or a flag indicating whether or not the user has successfully logged in. Another common use for session variables is to keep a running tally, such as the number of questions the user answered correctly so far on an online quiz, or the products the user selected so far from an online catalog.

Note: Session variables only work if the user's browser is set up to accept cookies. The server creates a session ID number that uniquely identifies the user when the session is first created, then sends a cookie containing the ID number to the user's browser. When the user requests another page on the server, the server reads the cookie in the browser to identify the user and to retrieve the user's session variables stored in memory on the server.

To Table of Contents Forward to next document