phpsymfonysessionpdo

Is there any way to add custom column to sessions table while working with pdo sessions


I Just configure Pdo sessions with symfony which work absolutely fine for me but now i am looking to add some extra fields like user IP, user id etc for make a report later on for which user login from which area so i find no way to add new columns into sessions table as it's working is little bit different

Here is my services.yaml file:

Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
            arguments:
    
                - !service { class: PDO, factory: 'database_connection:getWrappedConnection' }
                - { lock_mode: 1 }
    //framework.yaml 
    session:
            enabled: true
            gc_maxlifetime: 36000 #10 hours custom session time
            handler_id: 'Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler'
            save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
            cookie_secure: auto
            cookie_samesite: lax

The database table:

CREATE TABLE `sessions` (
   `sess_id` VARCHAR(128) NOT NULL PRIMARY KEY,
   `sess_data` BLOB NOT NULL,
   `sess_time` INTEGER UNSIGNED NOT NULL,
   `sess_lifetime` MEDIUMINT NOT NULL
) COLLATE utf8_bin, ENGINE = InnoDB;

Solution

  • Issue resolved by Creating Third Table by Name User Logs and Pass Session ID and User ID into it ( session and User table already created ) and some extra fields like ip location and so on. whenever user login make entry into this table