How to best replace global variables in Joomla extensions

291 Views Asked by At

The Joomla Extensions Directory puts pressure on developers not to use global variables (superglobals) such as $_SERVER, $_REQUEST, $_POST, $_GET, $_FILES, $_ENV, $_COOKIE, and $_SESSION to prevent SQL injections.

I'm mostly concerned about the $_GET variable which is widely used in my extension. What's the best way of replacing $_GET without having to make too many changes to the application?

1

There are 1 best solutions below

0
user3154108 On

The JApplication Object has a property input which holds all $_POST and $_GET Data for you. It works something like that:

$jinput = $JFactory::getApplication()->input;
$data = $jinput->get('getparamter');

There is plenty of documentation out there for for the use of that input object. Here is the API Documentation

$_SERVER, $_SESSION and others are replaces with userState and similar mechanisms, there really is no need to use of superglobals in Joomla.