Global variables in EmonCMS

Global variables can be declared in new modules, for example:

global $mysqli, $session;

There are many globals available, here we describe the more relevant ones.


Object that connects to EmonCMS database. It is an instance of the php class mysqli. You can see how to use it the php documentation:


Redis is an in-memory database (MySQL is in-disk). $redis is used to reduce the write load to the database. Anybody how can do this section??


Object that is an instance of the class Route. This class is defined in route.php Once the URL is decoded in index.php the $route object properties are set. For the following URL:


The $route properties are:

$route->controller = controller
$route->action = action 
$route-> subaction = subaction
$route-> format = format


Associative array that stores info about permissions after a user or a node has authenticated. $session['userid']: the session has been started by this user or a node that belongs to him/her


Object that is an instance of the class User. This class is defined in Modules/user/user_model.php This global variable is useful if you need to deal with: user login, user authentication, set/get user info like username, id, apikeys, email, language or timezone.

To know everything you can do using its methods, have look at the model.