Redirect on session timeout

Hi there

How can I achieve, a redirect if the session timeouts?
I would like to have the user redirected, as soon, as the session times out. Perhaps with a 30 seconds countdown.

Thank you and kind regards,
Stefan

You could do this with some client-side JavaScript that checks the session status periodically. Or just use a simple countdown from the last request.

Concrete CMS does have a heartbeat that will keep sessions open for authenticated users if the window is active, so depending on your use case, you may need to override that.

Thank you @Myq
I’ll try this.

Could someone please tell me, how to get the session timout i’ve set in the dashboard? There must be a simple way.

    $session = Core::make('app')->make('session');
    print_r($session->getMetadataBag());

This returns an array with the session metadata including sessen created and last used. but ther should be a lifetime which is allway 0.

Symfony\Component\HttpFoundation\Session\Storage\MetadataBag Object
(
    [name:Symfony\Component\HttpFoundation\Session\Storage\MetadataBag:private] => __metadata
    [storageKey:Symfony\Component\HttpFoundation\Session\Storage\MetadataBag:private] => _sf2_meta
    [meta:protected] => Array
        (
            [u] => 1629744057
            [c] => 1629742401
            [l] => 0
        )

    [lastUsed:Symfony\Component\HttpFoundation\Session\Storage\MetadataBag:private] => 1629744035
    [updateThreshold:Symfony\Component\HttpFoundation\Session\Storage\MetadataBag:private] => 0
)

I am probably looking in the wrong place.

Thank you for pointing me into the right direction.

Creating the cookie

    $cookie = Core::make('cookie');
    $cookie->set('testcookie','myValue');

The only problem is, this are httpOnly cookies.
Could someone please tell me, how to set the httpOnly to false?

Kind regards,
Steff

1 Like

Got it

$cookie->set('testcookie','myValue', 0, '/', null, false, false);

This way i am now able to get the cookie content with jQuery.

1 Like