How do I know how many seconds it will be until a php session expires?
I'm building a web application where users might spend a lot of time typing into big text fields, but for security reasons I still want sessions to time out after 开发者_高级运维a reasonably short period. I want to warn them if their session is about to expire so they can save or take some other action to keep it alive.
Any tips? thanks!
that's very easy. you have always session timeout left, which is 1440 seconds by default. to get actual value you can use
$seconds=ini_get('session.gc_maxlifetime');
but there is another way, better one. if your application get a text after session expired, save this text into session, ask for the password, and then save the text as if it was the regular submit.
You can store the expiration time in the database and then display an alert when that is about to happen. Or you could store the expiration time in a cookie value, and then have javascript that constantly checks to see if the session is about to expire.
精彩评论