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

dixitchopra's avatar

Session destroy

How can I set the time after which the session should expire? From mobile app, session shouldn't expire and if user has logged in from web, then it should expire in a day.

0 likes
10 replies
dixitchopra's avatar

I know, I can set session expire time but that won't help me because I want to set different session time for both app and website.

bashy's avatar

You may want to read up on how sessions work. If you want to change it depending on how they login you will need to adjust that on each login type.

dixitchopra's avatar

How can I adjust on each login? This is exactly what I am looking for. I tried readying up on how sessions work but couldn't find any clue.

pmall's avatar

Why not let everyone logged in for the same amout of time

unglued's avatar

In start of routes.php file you can change config

if(MyClass::isApp())
    Config::set('session.lifetime', 360*24*60);
1 like
davorminchorov's avatar

For the normal web app, you can set it in the config/session.php file but for the mobile app, you have to set the token expiration for the API. (I am assuming you are using an API of the same web app for the mobile version).

dixitchopra's avatar

@Ruffles How can I set the token expiration for the API? Is this the right approach or do I have to login whenever the session is expired by passing user credentials?

davorminchorov's avatar

I don't know how your API was implemented so if it's token-based authentication, there should be a method which sets the expiration date and that means, it will ask the user to login again.

1 like
dixitchopra's avatar

I didn't know about token based authentication. I should start implementing it for restful APIs. Currently, I was trying by using Oauth authentication and checking user by auth methods on each request.

Please or to participate in this conversation.