Home--> Articles -->Site Tools

Manipulate the variables of session

Post By tiantianxiao on 2008-9-26 15:57:57  [Reads:317]


The variables of session presents multiple and obvious interests. They permit to follow a visitor to allow him to recall some #118alues him at all times concerning (articles ordered in an application of on line sale, identification page by page for the rights of access to a private part, etc.). But used well, they will be of a precious interest to limit, sometimes considerably, the access to the data base.

Two exploratory things are to know:

Except reparamétrage specific side server, the life span of a session variable is of 20 minutes. It means that this variable "will live" as a long time that the author of the session will sail on the site. As soon as it remains inactive during 20 consecutive minutes, the variable of session "will die." To note that this life span of 20 minutes can be comfortably reconfigurée in the global.asa file thanks to the Session.Timeout function.

The fact to give a second #118alue to a same variable of session destroys the previous #118alue that had been assigned to him.

How to create and to exploit a variable of session?

Let's take a simple example: to allow the visitor to reach a site while personalizing its pages, you ask him, through a simple form, to identify by a pseudo any.

< FORM METHOD = "POST" ACTION = "ident.asp" > < P>Choisissez a pseudo: < BR > < INPUT MARKS = NAME "text" = "login" > < INPUT MARKS = been WORTH "submit" = "OK "> < FORM >

What will give:

Choose a pseudo:

On the following page (ident.asp), you will recover the variable of session of the following way:

<% Session ("login") = Request ("login")% >

You have only to reuse it like good seems you, for example:

< p > <% = Session ("login")% >, welcome on our service!< / p >

The variables of session will prove to be especially useful in case of seizure of a form on several pages: rather than to protect the data in the basis to every page and to recall the #118alues immediately in the same basis, he/it will be simpler and more reliable (limitation of the rise in charge generated by the ODBC connections) to stock every #118alue in a variable of session. To the final validation of the form, there will be a writing in the data base, and it will be sufficient to give to every field the #118alue <% Session ("nomvaleur")% >.

In a type of application a few different, those that will wish to develop an on line boutique with a virtual basket will be able to stock the two necessary #118alues of the content of the basket (réf. article and quantity ordered) in variables of session:

Article 1 > Reference: <% Session ("ref1")% >, Qty: <% Session ("qt1")% > Article 2 > Reference: <% Session ("ref2")% >, Qty: <% Session ("qt2")% > etc.

Sponsor Sites

Free Articles


Categories