简体   繁体   中英

how to Store User's Last Page Visited using session in php5?

how to Store User's Last Page Visited using session in php5?

when user come to my website & when he login then he will redirect to user panel of my site. but if user is not active more than 5 min then session will expire that time if user will active then it will redirect to login page.

now i want when user relogin then he will redirect to his last visited page|(where his session expire last time).

If the session has expired, the last page value won't be there. You could:

  • set a cookie to store the last URL
  • inspect HTTP_REFERER to see where the user came from. Store this in the (new) session and then use redirect to it once they've successfully logged in again.

Only way to achieve this is by storing the last visited page into the database OR a cookie. You can never know when a session times out and after the timeout any information will be lost. You can also not rely on the REFERRER information as it's up to the browser to send the referer (what happens if a third party site links to you login page?).

Best advise: Use a cookie.

在会话中存储页面,然后在sessionEnd上将页面保存在数据库中

This shouldn't be necessary at all.

At the time you redirect the user to the login page, you already know the URL the user requested. Add that URL as a parameter to the login page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM