CGI: State
Some user interactions can be dealt with in one action, e.g. user
fills in a comments form that's emailed to you.
Others need a sequence of actions, one feeding the next, e.g. browsing
a virtual mall and filling a virtual trolley; a list of items in the
trolley needs to be kept somewhere.
"State" is usually a collection of facts that you need from one
transaction to the next one for that user, e.g. the list of items
selected so far. You can either send that whole collection to the
client, for them to echo back when ready; or, you can store them,
e.g. in a file, and tag them with a unique identifier.
This can easily
be done using a sequential number generator, like the visitor counter.
You name that file with the id, and pass it to the client, in the HTML.
However you then have to take care of housekeeping the state
files, e.g. by periodic clean-up tasks.
Instead of sequential numbers, you might use something else, e.g.
# No client-side state!
$file = "/tmp/".$ENV{'REMOTE_HOST'};
..but it might not be unique..
- Hidden Variables.
<FORM ...>
<INPUT TYPE="hidden" NAME="Sid" VALUE="8663">
</FORM>
- Path Info in hyperlink URLs.
<A HREF="/cgi-bin/prog?Sid=8663">
Click Here!</a>
- Path Info in the Form action URL.
<FORM ACTION="/cgi-bin/prog?Sid=8663">
...
</FORM>
|