You have several options: 1 is the "Referer" header. This field will contain the URL where the browser was finally ... So you could see on the login page, there was the last page that they link to here, or somewhere else.
This will work, but not complete, some people / companies will filter out links, etc., and some browsers may allow users to enable it, so you will not get a link to the page in which they were last visited.
The BEST bet is to set a cookie when the user logs in, and then if the user requests a page that requires a login, your code simply checks for the current cookie value. If he is there, the user has already registered and you can show the page ... if you do not send them, YOU SHOULD LOGIN TO MAKE THIS page.
source share