Setting a Session Life in PHP

Asked

Viewed 32 times

-2

I’m trying to define the lifespan of my sessions, but nothing I’ve seen so far has worked.

I set the time of 1 minute and did several tests to see if it works:

#Teste 1 - Setei o cache para 1 minuto
session_cache_expire(1);
session_start();


#Teste 2 - Setei o Lifetime do cookie para 60 segundos
define("LIFETIME", 60);
session_set_cookie_params(LIFETIME);
session_start();


#Teste 3 - Setei diretamente no php.ini o maxlifetime e o cookie para 60 segundos
session.gc_maxlifetime = 60
session.cookie_lifetime = 60

Nothing has worked so far, someone could help me please?

  • How did you find out it didn’t work?

  • @Thank you for the question. I click on other pages and remain logged in. When I do this same procedure after about 30 minutes then I am disconnected because the session is with the default lifespan. I would like to control this time because I need to stay connected for at least 24 hours.

  • 1

    Just because you posted it is not possible to know what happens, but it may be another problem: check if you are renewing the cookie on following pages (if the cookie has time, you need to "renew" it in consecutive accesses, otherwise it wins even with you using the site) or leave the cookie without time (then becomes a session cookie, which the browser keeps until close).

  • 1

    gc_maxlifetime is not used for this and cookie_lifetime is to control the cookie itself, not the session exactly. Your problem can be many things, even more if you are using things like API to work with Angular, Vue, etc with CROSS-Omain, then you will have complicated questions about Xmlhttprequest (for example, the cookie is not propagated outside the "ajax", which can be solved, but we do not know if this is your problem), I recommend that you create a [mcve] with a step by step in a very simple way that we can execute the problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.