Jump to content

[SOLVED] Calling session variables from hooks


esspea
 Share

Recommended Posts

Hello all,

So, from within a hook I can:

Directly call a cookie variable by: $_COOKIE['varname'] and I can directly call server data by: $_SERVER['REMOTE_ADDR']

but $_SESSION['varname'] does not work, and neither does $session->get('varname').

How can I call a session variable from within a hook?

Best regards,

Snorri

 

Link to comment
Share on other sites

$session->foo = 'Foo!';
$wire->addHookBefore("Page::render", function ($event) {
  bd('hook fired');
  bd($this->wire->session->foo);
  bd($this->wire()->session->foo);
  bd($event->wire->session->foo);
  bd($event->wire()->session->foo);
  bd($event->session->foo);
  bd($event->session->get('foo'));
  bd(wire()->session->foo);
});

Choose whatever you like bist ? I prefer $this->wire->session->foo

  • Like 2
  • Thanks 2
Link to comment
Share on other sites

  • esspea changed the title to [SOLVED] Calling session variables from hooks

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...