Elxis CMS Forum
Support => Elxis 4.x/5.x DEV => Topic started by: Tank on June 03, 2013, 17:06:14
-
Is it possible to check if a user is logged into Elxis from an external file within the root folder of Elxis?
I have a standalone file which does some special functions in a root filebut only want admin to access it.
If possible, how can I do this?
Thanks
-
Depends on the session handler. If it is "none" or "files" you can get the information from the super global variable $_SESSION variable like that:
$_SESSION[$namespace][$var]
The default namespace for Elxis is "elxis" and the user group id is available in variable "gid", so: $_SESSION['elxis']['gid'] , if is set it will provide you the user's group id.
If this value equals to 1 then it is an admin user.
If the session handler is "database" (default option) you have to connect to the Elxis database to get the session information and initialize session.
Note
Elxis session data might be encrypted. You will have to decrypt it in this case using a mechanism similar to the one provided by the Elxis' Crypt helper.
includes/libraries/elxis/helpers/crypt.helper.php
An alternative solution is to load Elxis in your external file. You can use the standard loader (includes/loader.php), a modified copy of the standard loader (comment line 230), or the mini loader available in the installation folder.
includes/install/inc/miniloader.php
Initializing and connecting to Elxis db with the miniloader
require_once(ELXIS_PATH.'/includes/install/inc/miniloader.php');
require_once(ELXIS_PATH.'/includes/libraries/elxis/database.class.php');
$params = array(
'dbtype' =>'xxx',
'host' => 'xxx',
'port' => 'xxx',
'dbname' => 'xxx',
'username' => 'xxx',
'password' => 'xxx',
'persistent' => 0,
'dsn' => 'xxx',
'scheme' => 'xxx',
'table_prefix' => 'xxx',
'debug' => 0
);
$db = new elxisDatabase($params, array(), false);
$ok = $db->connect($params['dsn'], $params['username'], $params['password'], array(), true);
-
Sorry for my late reply. Thank you for that helpful information, datahell!