Jump to content

Hooking Session::init


Pete
 Share

Recommended Posts

Hi guys

I'm trying to hook Session::init in a module and essentially replace what it does.

The reason for this is that I am trying to integrate a third-party application that also has user accounts and when ProcessWire's session::init() function is called it overrides the session from the other application and I can't access the session data from the other system.

I am thinking I could get around this in a module if I can hook the session::init function, grab the user ID from the session from the other application before it is overridden, store the user ID in a session var, let ProcessWire do its thing and then re-load the user in the other app after ProcessWire is loaded.

I can't see any other way around the session collision here so this seems to be as elegant as I can make it and, as far as I am aware, is still safe.

My hook looks something like this (it's in a module, extra code stripped to keep it short!):

public function init() {
        $this->session->addHook('init', $this, 'sessionreplace');
}
 
public function sessionreplace($event) {
        // My custom code here
 
        @session_start(); // This is the same as in Session::init
        $event->replace = true; // I think this is required?
}

I'm sure I'm doing something wrong though as nothing I do here works.

I also have this feeling that session_start() runs before other modules are loaded so this will never work and I will have to think of something else.

Link to comment
Share on other sites

Thanks, I was afraid that would be the case.

Ideally I would like this to be a module that could be released in future, so edits to the config file are out for this, however I think I may have some other options.


EDIT: unless of course my module installation just appends some code automatically to the config file - that could also work :)

Link to comment
Share on other sites

Ah, yeah, now after putting on my glasses I see that you have written "config file". This, (reading without glasses) and the fact that I'm currently working on a little autoload module that tweaks $config (only the variable / object, not the file content) was enough to make me not seeing / thinking clear.

(This has nothing to do with the bottle cognac whose content decreases continuously here.) :lol:

Link to comment
Share on other sites

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...