Database Reference
In-Depth Information
tion. A special SSI command relates to the execution of a subprogram similar to a
CGI script. On parsing and recognizing this command, a Web server can initiate the
execution of a subprogram and include its result in the web page to be delivered to
the browser. And this subprogram can be a script to access a database, perform data-
base operations, and produce results from the database.
Cookies
As we have mentioned several times in our previous discussions, HTTP is a state-
less protocol. But for interactive applications such as database applications, the
application program must know whether a transaction is part of an interactive
session. As you know, under HTTP, the Web server maintains no state information.
That is, when a user contacts a website through an URL submitted at the client site
using a browser, the Web server does not know whether this is the user's first visit
or thirtieth visit.
For example, in an electronic shopping encounter, the application program must
know which shopping cart belongs to whom. Let us say that the database table rep-
resenting a shopping cart with three items so far stores the user's name and pass-
word that came in as part of the registration. Now the user returns to the website
through the browser to add a fourth item. Because of the stateless nature of HTTP,
the server has no idea whether the user has returned for a fourth time or this is a
brand new first visit. Any CGI script interfacing with the database server cannot
receive any state information from the Web server.
Let us stop the discussion right here. Imagine that when the user returns to the
website, the CGI script is able to request the browser for a file stored at the browser
site containing user registration information. Suppose from the registration file
received, the script is able to determine that the user is the same person with a
virtual shopping cart with three items. Then this file stored at the browser end
somehow is able to maintain state to the extent required by the shopping cart appli-
cation. This small text file stored on the Web client system is known as a cookie (just
called cookie for no valid reason). More formally, these files are referred to as per-
sistent client state HTTP cookies. A cookie may persist at a client site for many
months or even years.
How Cookies Work The use of cookies makes CGI scripts more interactive. A
cookie is a small file created by a CGI script and stored at the browser site. In its
simplest form, a cookie consists of a name-value pair. A developer may choose any
such pair to create a cookie. More advanced implementations include expiration
dates and restrictions on which Web pages can see the cookie as part of the cookie
definition.
In our electronic shopping example, when the user visits the website to begin
shopping, the CGI script creates a cookie, perhaps consisting of name and password
as the name-value pair, and sends it to the user's browser. The browser receives the
cookie and stores it on the hard drive at the client site. At a later time, when the
user goes back to add items to the shopping cart, the CGI script requests for
the cookie from the client side and compares with the registration information
stored in the database during the previous visit. Based on the results of the com-
parison, the interaction proceeds further.
Search WWH ::




Custom Search