1

I am using FOSUserBundle to manage users, and sessions are saved in database thanks to PdoSessionStorage.

I would like to add fields in my session table :

  • user_id : which is a foreign key referencing the ID of logged user
  • ip : IP address of the user logged in
  • end_time : the time when the user has logged out

Here is my app/config/config.yml file :

framework:
    session:
        default_locale: %locale%
        auto_start: true
        lifetime: 72000
        storage_id: session.storage.pdo

parameters:
    pdo.db_options:
        db_table: session
        db_id_col: session_id
        db_data_col: value
        db_time_col: time

services:
    doctrine.dbal.default.wrapped_connection:
        factory_service: doctrine.dbal.default_connection
        factory_method: getWrappedConnection
        class: PDO
    session.storage.pdo:
        class:     Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage
        arguments: [@doctrine.dbal.default.wrapped_connection, %session.storage.options%, %pdo.db_options%]

How can I do that ?

Do I need to extend PdoSessionStorage class ?

If so, how to do this ?

1 Answer 1

2

Simply extend PdoSessionStorage to add your infos. You are free to add any dependency to the session.storage.pdo.

About the User ID, you don't have to do it, it's already in the session data (you will have to decode them).

Sign up to request clarification or add additional context in comments.

1 Comment

for unserializing the sess_data the class provided here was useful to me: stackoverflow.com/a/9843773/2848530

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.