0

I already setup the environment mode, but it still manually.

I want to change the development mode based on who login to my system and checked it by usertype session.

i try to create like this on root index.php file:

if($this->session->usertype == '1'){
    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
}
else{
    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production');
}

But, i got this error:

Fatal error: Uncaught Error: Using $this when not in object context in .....

Any solution will be appreciate. Thank you

wakped
  • 67
  • 7
  • Hi, maybe [this](https://stackoverflow.com/questions/2350937/php-fatal-error-using-this-when-not-in-object-context) can be of help – Chiel Jun 12 '20 at 10:28
  • Environment is intended to let your code know if it's running on a development box (and thus be much more verbal about errors, for instance) or a production server (much less verbosity, among other things, to prevent information disclosure breaches). They are not intended to display different versions depending on the type of user. – Javier Larroulet Jun 13 '20 at 04:00

1 Answers1

0

It's not possible to access the session over $this in index.php.

Try something like this:

if ($_SESSION['usertype'] == 1) {
//your code here
} else {
// your code here
}
HausE
  • 11
  • 1
  • 4