tags:

views:

47

answers:

4

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).

A: 

store page in session and then save page in database on sessionEnd

x2
can u plz provide me code because i am new in php
Pratikg88
+1  A: 

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.
AlexJReid
+1  A: 

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.

halfdan
@halfdan thanks for suggestion
Pratikg88
A: 

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.

Pekka