We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to Redirect to already visited route after login?

If I type in a back-end URL - e.g. https://example.com/admin/stories - and I'm not logged in, after logging in, I expect to be redirected to the page I originally tried to browse - i.e. https://example.com/admin/stories

How can I add this functionality in Phalcon? Any example would be great.


Better use forwards to don't lose the url. Implement a event dispatcher like before:executeRoute check docs

Good luck

If you're being redirected, then you've written code to do that redirection. In that same code block, find the current URL and store it in the session. Then, after a successful login, if that session variable exists, redirect the user back to that URL.