Storing User Parameters

HTTP does not support protracted connections. A new connection is created to receive each file in a page (i.e., a script, image, Flash animation, etc.). Consequently, the server cannot control whether the same user requested two different item (e.g., a script and an image), because for each of these a different connection would be created.

Page transitions also create new server connections; therefore, pages cannot be interlinked nor have common parameters. There are three ways to save parameter values when moving from one page to another. These are the following:

  • Cookies: files stored on the client's computer. These can be:
    • Temporary: stored in the memory of the client's computer only during the specific server connection.
    • Permanent: stored on the client's hard drive until the specified time.
  • Sessions.
  • Implement your own connections, with the necessary parameters saved in database table and linked to the client.

User parameters are not saved and have to be pulled along when moving from page to page. Suppose that the design of your site can change dynamically and that a user selected a certain color theme for a certain page. Now when any other page from your site is requested by the same user, it has to be displayed using the color theme selected. This means the theme's name or number has to be passed from page to page.

It would not hurt either to be able to store the user-theme pair long term, in case the user decides to return to the site some time later. He or she will be pleasantly surprised to see that all the page settings have been preserved and don't have to be fiddled with again.

Before exploring the ways of implementing data storage, we have to establish what data and for what purpose we want to store. In this respect, it is desirable to group data by how long it is to be stored and how important it is. The two groups are the following:

  • Variables that are to be stored until new values are supplied by the user. Examples of such variables are site configuration settings, shopping cart parameters, and the like. Data of this type must be saved even after users finish working with site for when they come back later.
  • Data for a specific session. A good example of such data is a user name. If the site uses authorization, user name must be saved when pages are switched. But when a user finishes working with the site (closed the browser) and comes back to it later, the authorization processes has to be repeated.

Most suitable for short-term data storage are session variables; for long-term data storage of user configuration settings cookie files can be used.

Tag: PHP Development | Date:4/11/2010 6:33:57 PM