What keeps a php session alive?

后端 未结 1 1345
野的像风
野的像风 2021-02-11 15:32

Are sessions only kept alive each time you access a page with session_start(); or do other pages keep it alive too?

Example (with 30 minute

1条回答
  •  一生所求
    2021-02-11 16:09

    There is always a session cookie set in your browser whenever you access a page which has session_start(). The cookie name will PHPSESSID if the website is using PHP(although the name can be changed). This session cookie contains a session id which helps the browser to maintain that session with the server.

    You can check manually by browsing any website which has your session and then delete your browser cookies, your session will be lost.

    In your case both 1 & 2 are correct.

    2 is correct because the user already has accessed a page which has session_start() and your session id will be set for the next 30 mins and it will be present even if you accesse a page which does not have a session.

    NOTE: But the page which you will be visiting if contains session_destroy(), your session will be destroyed.

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