17.
Variable Substitution
Up one level
Syntax: '%' + variable name + '%'
Example 1. Connecting securely to a Spatial Database
You want to map some senstitive data held in a PostGIS database. The username and password to be used for the database connection are held in 2 cookies previously set by a seperate authentication mechanism, "uid" and "passwd".
CONNECTION "user=%uid% password=%passwd% dbname=postgis"
Example 2. Handling temporary files
You have a user based discovery application that generates shapefiles and stores them in a user's home directory on the server. The "username" comes from a cookie, the "filename" comes from a request parameter.
DATA "/home/%username%/tempshp/%filename%"
This feature is only available in the CGI version of MapServer through a mapfile pre-processor. If you are using MapScript, you will have to code the substitution logic into your application yourself (By writing your own pre-processor).
Expression substitution
you'd write the mapfile
entry like so:
LAYER
NAME 'fastvisa'
...
CLASS
EXPRESSION ([FNR]=%myid%)
END
END
and would have a URL like ...&myid=210176493&...
The advantage here is the you make the decision to enable that level of configuration, plus you can apply a regex filter to the value passed in from the URL and if the value doesn't match that pattern then no substitution is made:
LAYER
NAME 'fastvisa'
...
METADATA
myid_validation_pattern '^\d{9}$'
END
CLASS
EXPRESSION ([FNR]=%myid%)
END
END
In this example the input value for myid must consist of exactly 9 digits.
Extracted from: http://www.nabble.com/mapserver-5-expression-tf4347481.html#a12414895
Supported keywords