Personal tools
You are here: Home Documentation References

17. Variable Substitution

Document Actions
Up one level
New in MapServer 4.0, variables can be substituted within mapfile parameter values. At this time, cookie and CGI parameter values are supported. This allows mapserver mapfiles to be aware of a user's cookies (Good for implementing security), or non-mapserver request parameters (Good for integrating with other systems).

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).

by Jeff McKenna last modified 2005-12-15 19:49

Supported keywords

Posted by Francisco Regodón at 2007-04-10 04:49
In Mapserver 4.10.1 the only keywords that support variable substitution are: DATA TILEINDEX CONNECTION FILTER and EXPRESSION

Expression substitution

Posted by Randy How at 2007-10-23 17:52
Using runtime substitution. Presumably
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

Powered by Plone