Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ZPNDSTR's avatar
Level 11

Session database table without IP

I'm using database storage for laravel sessions and it's working alright. But I'd like not to save IP-Addresses of the users, or if needed for security reasons only as hashed value. Unfortunately I did not find any way to make something like this work. Anyone an idea how to get this working?

0 likes
1 reply
Cinek's avatar

I think that you have to extend default session handler and write your own logic to store session in database. You can extend default DatabaseSessionHandler in your own class (ex. CustomSessionStore.php) and override getDefaultPayload function. Then u can register your own session driver like this: AppServiceProvider.php

Session::extend('custom', function($app) use ($connection) {
            $table   = Config::get('session.table');
            $minutes = Config::get('session.lifetime');
            return new CustomSessionStore($connection, $table, $minutes, $app);
        });

and set it in config: session.php

'driver' => 'custom',

Please or to participate in this conversation.