CGI environment variables and Packaging information





Possibly the most useful of environment variables is the QUERY_STRING variable.

The QUERY_STRING environment variable can only store one string without spaces, but ideally we would like it to store more information. For example, when searching a database across the Web we would like to pass information not only about what string should be searched for, but also what kind of fields should searched, whether the search should be case sensitive, and so on. Also, it would be nice to include spaces in search strings.

As it happens this is all possible by encoding spaces and values of different variables. Suppose we want to send the following information to our CGI script:

star = Eastwood
cert = 15
movie = Pale Rider

Clearly we need to package this information into a single string for the QUERY_STRING environment variable. The way it is done is to put an & between each variable setting and replace each space by a + sign. From the above we get

QUERY_STRING = "star=Eastwood&cert=15&movie=Pale+Rider"