Pete Posted November 16, 2014 Posted November 16, 2014 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.
horst Posted November 16, 2014 Posted November 16, 2014 Hint: https://processwire.com/talk/topic/142-make-session-start-in-session-overridable-from-a-module/#entry1002 1
Pete Posted November 16, 2014 Author Posted November 16, 2014 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
horst Posted November 16, 2014 Posted November 16, 2014 the session is initiated before the plugin modules are because in PHP subsequent calls to session_start() are ignored You makes me curious and/or puzzled.
Pete Posted November 16, 2014 Author Posted November 16, 2014 I meant that during installation my module could add code to the config.php file similar to the topic you linked to to do something there before PW's session starts. 1
horst Posted November 16, 2014 Posted November 16, 2014 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.)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now