Let say I have 2 pages and one is called page A which is the index page and the other page B and assuming the user has to login to page B before he can post comment or click on like button and the user is being redirected from page B to the logging page, how can the user be redirected back to page B after logging. That is the user should be redirected automatically back to page B instead of page A which is the index page.
P.s. I will prefer it if example is in MVC pattern
You need to make sure to check the return_url value though before blindly redirecting to it, to avoid security exploits (for example check that it doesn’t start with http:// or https:// or when it does make sure it’s your own domain and not some external domain)