I don't know if there is a better way, but I always do this:
When the user is on the About page and clicks on the login, take the URL of the page, possibly base64_encode on it, and then send it to the login page via GET as a parameter. On the login page, if the credentials are valid, you take this parameter from GET, base64_decode and redirect there.
If you do this only for the main pages, you can only get the controller from the URL, but if you want to apply it on every page ( /controller/method/var1/var2 ), take the whole URL or the whole URL minus url code.
Let me know if this tip helped.
source share