When to use session variables to define recordsets
Session variables are useful if you want to customize the recordsets in your site to suit the user's preferences. For example, suppose a visitor at a music site is not interested in jazz. You can store the visitor's dislike in a session variable, then use the variable in all your SQL statements to filter out jazz tracks from all the recordsets the user generates during his or her visit.
You can also use session variables to restrict the data the user sees during a visit (for usability or security reasons). Suppose you're building a web application that lets users search a database of restaurant reviews by cuisine (Italian, French, Indian, and so on) and by price range. Because the restaurants in the database are spread over several cities, you'd like to give the user the ability to filter out all restaurants that are not in his or her city. For usability reasons, you don't want to ask the user to enter the city every time he or she performs a new search. To solve this problem, you decide to store the user's city in a session variable, and use that variable to automatically restrict all searches to that city.
|