Search code examples
phpsession-management

Implementing own Session Management in PHP


What options are there to implement an own session management in PHP?

Is there a nice way to implement a component which performs all session tasks? How can i construct a class which receives the HTTP Request and Response during one request process? I only found the option "session_save_handler" which seems to define the storage handler. What I need is to replace the whole session management. Is there another way using the PHP configuration or do I have to implement my own controller which receives all requests and calls my session management?

Thanks for your help

Regards Michael


Solution

  • No, I'm sorry to say, there is no interface to switch the built in 'modules' to your own. There are some hooks ( e.g: session_save_handler(), set_error_handler() ), and that's unfortunately it.

    The $_SESSION is a 'super global' and should IMO not be set directly either way if you're working on a bigger projects. Then it would be better to use a custom class responsible for handling sessions. Will make the code easier to debug and such on.