PHP session timeout htaccess file

后端 未结 1 1244
慢半拍i
慢半拍i 2021-01-21 02:10

Hi i\'m new to programming but am currently working on a session timeout problem. Basically my session keeps timing out even though i\'ve changed the session.gc_maxlifetime. I

相关标签:
1条回答
  • 2021-01-21 02:52

    PHP doesn't do with session cookies what you might think it does...

    php_value session.gc_maxlifetime "86400"

    This merely sets the time after which garbage collection may occur - since there's only a very small chance that the session data will be garbage collected after this time this is unlikely to be the culprit.

    php_value session.cookie_lifetime "86400"

    This sets the time at which the session cookie expires... but it doesn't update at session_start() therefore, if you start the session on one page, that sets the clock ticking. Moving from page to page won't reset the "clock" so a session with a cookie_lifetime of 600 will expire 10 minutes after it was started not after 10 minutes of inactivity - you may be seeing this behaviour.

    Your best bet is to set php_value session.cookie_lifetime "0" this means that the session cookie will expire only when the user closes their browser.

    If you want to handle an arbitrary expiry that triggers after a period of inactivity it's best to do that in the PHP code by setting a variable within the session, something like $_SESSION['expires'] and checking/updating/handling that at the start of every page.

    0 讨论(0)
提交回复
热议问题