I'm attempting to retrieve a cookie in index.php to record the value in a global_variable. I'd like to do it this way to avoid including PHP/plugin code on every template. Currently I have;

$assign_to_config['global_vars']['user_location'] = $this->EE->input->cookie('user_location');

However this throws the error;

Fatal error: Using $this when not in object context in /xx/xxx/xxx/index.php on line 28

Am I allowed to do this sort of thing?


This will not work as object isn't being initialized. You can use PHP $_COOKIE to get it.

$assign_to_config['global_vars']['user_location'] = $_COOKIE['user_location'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.