Source code for file /joomla/environment/request.php
Documentation is available at request.php
* @version $Id: request.php 9944 2008-01-14 21:10:22Z eddieajau $
* @package Joomla.Framework
* @subpackage Environment
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* Create the request global object
$GLOBALS['_JREQUEST'] =
array();
* Set the available masks for cleaning variables
define( 'JREQUEST_NOTRIM' , 1 );
define( 'JREQUEST_ALLOWRAW' , 2 );
define( 'JREQUEST_ALLOWHTML', 4 );
* This class serves to provide the Joomla Framework with a common interface to access
* request variables. This includes $_POST, $_GET, and naturally $_REQUEST. Variables
* can be passed through an input filter to avoid injection or returned raw.
* @package Joomla.Framework
* @subpackage Environment
* Gets the full request path
return $uri->toString(array('path', 'query'));
* Gets the request method
$method =
strtoupper( $_SERVER['REQUEST_METHOD'] );
* Fetches and returns a given variable.
* The default behaviour is fetching variables depending on the
* current request method: GET and HEAD will result in returning
* an entry from $_GET, POST and PUT will result in returning an
* You can force the source by setting the $hash parameter:
* method via current $_SERVER['REQUEST_METHOD']
* @param string $name Variable name
* @param string $default Default value if the variable does not exist
* @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
* @param string $type Return type for the variable, for valid values see {@link JFilterInput::clean()}
* @param int $mask Filter mask for the variable
* @return mixed Requested variable
function getVar($name, $default =
null, $hash =
'default', $type =
'none', $mask =
0)
// Ensure hash and type are uppercase
if ($hash ===
'METHOD') {
$sig =
$hash.
$type.
$mask;
if (isset
($GLOBALS['_JREQUEST'][$name]['SET.'.
$hash]) &&
($GLOBALS['_JREQUEST'][$name]['SET.'.
$hash] ===
true)) {
// Get the variable from the input hash
$var =
(isset
($input[$name]) &&
$input[$name] !==
null) ?
$input[$name] :
$default;
elseif (!isset
($GLOBALS['_JREQUEST'][$name][$sig]))
if (isset
($input[$name]) &&
$input[$name] !==
null) {
// Get the variable from the input hash and clean it
// Handle magic quotes compatability
$GLOBALS['_JREQUEST'][$name][$sig] =
$var;
elseif ($default !==
null) {
// Clean the default value
$var =
$GLOBALS['_JREQUEST'][$name][$sig];
* Fetches and returns a given filtered variable. The integer
* filter will allow only digits to be returned. This is currently
* only a proxy function for getVar().
* See getVar() for more in-depth documentation on the parameters.
* @param string $name Variable name
* @param string $default Default value if the variable does not exist
* @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
* @return integer Requested variable
function getInt($name, $default =
0, $hash =
'default')
* Fetches and returns a given filtered variable. The float
* filter only allows digits and periods. This is currently
* only a proxy function for getVar().
* See getVar() for more in-depth documentation on the parameters.
* @param string $name Variable name
* @param string $default Default value if the variable does not exist
* @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
* @return float Requested variable
function getFloat($name, $default =
0.0, $hash =
'default')
* Fetches and returns a given filtered variable. The bool
* filter will only return true/false bool values. This is
* currently only a proxy function for getVar().
* See getVar() for more in-depth documentation on the parameters.
* @param string $name Variable name
* @param string $default Default value if the variable does not exist
* @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
* @return bool Requested variable
function getBool($name, $default =
false, $hash =
'default')
* Fetches and returns a given filtered variable. The word
* filter only allows the characters [A-Za-z_]. This is currently
* only a proxy function for getVar().
* See getVar() for more in-depth documentation on the parameters.
* @param string $name Variable name
* @param string $default Default value if the variable does not exist
* @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
* @return string Requested variable
function getWord($name, $default =
'', $hash =
'default')
* Fetches and returns a given filtered variable. The cmd
* filter only allows the characters [A-Za-z0-9.-_]. This is
* currently only a proxy function for getVar().
* See getVar() for more in-depth documentation on the parameters.
* @param string $name Variable name
* @param string $default Default value if the variable does not exist
* @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
* @return string Requested variable
function getCmd($name, $default =
'', $hash =
'default')
* Fetches and returns a given filtered variable. The string
* filter deletes 'bad' HTML code, if not overridden by the mask.
* This is currently only a proxy function for getVar().
* See getVar() for more in-depth documentation on the parameters.
* @param string $name Variable name
* @param string $default Default value if the variable does not exist
* @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
* @param int $mask Filter mask for the variable
* @return string Requested variable
function getString($name, $default =
'', $hash =
'default', $mask =
0)
// Cast to string, in case JREQUEST_ALLOWRAW was specified for mask
return (string)
JRequest::getVar($name, $default, $hash, 'string', $mask);
* Set a variabe in on of the request variables
* @param string $name Name
* @param string $value Value
* @param string $hash Hash
* @param boolean $overwrite Boolean
* @return string Previous value
function setVar($name, $value =
null, $hash =
'method', $overwrite =
true)
//If overwrite is true, makes sure the variable hasn't been set yet
// Clean global request var
$GLOBALS['_JREQUEST'][$name] =
array();
// Get the request hash value
if ($hash ===
'METHOD') {
$_REQUEST[$name] =
$value;
$_REQUEST[$name] =
$value;
$_COOKIE[$name] =
$value;
$_REQUEST[$name] =
$value;
$_SERVER['name'] =
$value;
// Mark this variable as 'SET'
$GLOBALS['_JREQUEST'][$name]['SET.'.
$hash] =
true;
$GLOBALS['_JREQUEST'][$name]['SET.REQUEST'] =
true;
* Fetches and returns a request array.
* The default behaviour is fetching variables depending on the
* current request method: GET and HEAD will result in returning
* $_GET, POST and PUT will result in returning $_POST.
* You can force the source by setting the $hash parameter:
* method via current $_SERVER['REQUEST_METHOD']
* @param string $hash to get (POST, GET, FILES, METHOD)
* @param int $mask Filter mask for the variable
* @return mixed Request hash
function get($hash =
'default', $mask =
0)
if ($hash ===
'METHOD') {
// Handle magic quotes compatability
* Sets a request variable
* @param array An associative array of key-value pairs
* @param string The request variable to set (POST, GET, FILES, METHOD)
* @param boolean If true and an existing key is found, the value is overwritten, otherwise it is ingored
function set( $array, $hash =
'default', $overwrite =
true )
foreach ($array as $key =>
$value) {
* Checks for a form token in the request
* Use in conjuction with JHTML::_( 'form.token' )
* @param string The request method in which to look for the token key
* @return boolean True if found and valid, false otherwise
* Cleans the request from script injection.
if (isset
( $_SESSION )) {