Last reviewed: 17 Nov 2005, Joomla 1.0.3

mosGetParam is a frequently used function in Joomla components and modules.  It allows you to easily retrieve the value of a parameter passed from a previous page, for example, from filling in a form or clicking on a link.  By default the data returned will be stripped of HTML tags and will have leading and trailing whitespace characters removed.

If magic_quotes_gpc is off then mosGetParam will automatically escape single quotes, double quotes, backslashes and nulls by adding a backslash character (unless the _MOS_ALLOWRAW option is used). Note that with magic_quotes_gpc on all entries in $_ENV, $_GET, $_POST, $_REQUEST, $_COOKIE, $_GLOBALS and $_SERVER arrays are automatically escaped by PHP. This behaviour is not overridden by using the _MOS_ALLOWRAW flag. See also magic quotes in the PHP manual.

Note that if you intend to store the data returned by a mosGetParam call in a database field then you will need to perform additional database-specific escaping. See database->getEscaped.


mixed mosGetParam ( array &$arr, string $name [, mixed $default [, int $mask ]] )

is the array that the parameter will be retrieved from.  This can be any array but the most commonly used ones are $_POST and $_GET.
is the name of the parameter field to be retrieved.
is the optional default value that will be returned if $name is not present in $arr.  This parameter is optional and if omitted will default to null.
is an optional parameter containing one or more of the following flags:
Do not strip HTML tags from the data.
Do not remove leading and trailing whitespace characters.
Do not filter the data.  Introduced in Joomla 1.0.
If omitted this parameter defaults to 0 (that is, data will be stripped of HTML tags and leading and trailing whitespace characters).

Defined in

(includes/joomla.php prior to Joomla 1.1)
(includes/mambo.php prior to Joomla 1.0)


Example 1: A typical use where the parameter 'task' is retrieved from the set of parameters passed in a URL from a previous page.  If 'task' is not present then $task will be set to an empty string.

// Get task value.
$task = mosGetParam( $_GET, 'task' );
echo $task;

Example 2: Force an expected integer to be an integer (wth a default value of zero).

// Get an integer.
$id = intval( mosGetParam( $_REQUEST, 'id', 0 ) );
echo $id;

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Tuesday, 03 January 2006 )