Gathering the information to store in a session variable
Before you can display the value of a session variable, you must gather the information you want to maintain for the duration of the user's session, then store it in a session variable in your source code.
This article describes how to gather the information using one of two methods: an HTML form or hypertext links containing URL parameters. Here's an example of links with URL parameters that send information to the server for storage in a session variable:
<a href="showroom.cfm?currency=USD">U.S. Dollar</a><br>
<a href="showroom.cfm?currency=EUR">Euro</a><br>
<a href="showroom.cfm?currency=YEN>Japanese Yen</a>
If the user clicks the Euro link, the browser sends the URL parameter, currency=EUR , to the server. The server places the URL parameter in a ColdFusion variable called url.currency, then runs the ColdFusion page, showroom.cfm. This page contains code that copies the value of url.currency into a session variable, as described in the next section of this article.
Note: You can also gather information for session variables from cookies stored on the user's computer, from the HTTP headers sent by the user's browser with a page request, and from a database. However, these sources are not covered in this article.
|