Expire session automatically and detect if the session has expired in Codeigniter

后端 未结 5 1648
粉色の甜心
粉色の甜心 2021-02-06 13:37

I\'ve seen plenty of questions here about my topic but it seems I still haven\'t found my answer. What I\'m actually looking for is when the session expires the user will be aut

5条回答
  •  一整个雨季
    2021-02-06 14:34

    Although not 100% reliable, you could set a cookie on the users machine. I would recommend setting the expiry about an hour in advance.

    With every page that you wanted to know if the session had expired, you could check to see if both the cookie and the session existed. If it does...continue. If only the cookie remains, then you know that the session has expired and you need to redirect them to the page that you referred to in your question. If neither are present, then there is a problem and the user needs to restart everything.

    Of course, for every page that a session is instantiated, the session expiry will restart, so you will need to reset the cookie. It could be a bit tedious, but it is what I would recommend.

提交回复
热议问题