How to: Redirect to requested page after login

Sometimes, in our AppGini applications we'd like to share data with co-workers or other users by sending a link via email, for example. Unfortunately, this does not work as expected, by default.

I am going to show a very simple, solution, based on our AppGini Helper Javascript Library.

AppGini default behaviour

By default, if we are not logged in already, AppGini redirects us to the login-page first, then to the homepage (index.php) after login.

graph LR S((Start)) ==> A{Authorized<br>?} A -. yes .-> P([Requested Page]) A == no ==> L([Login]) L ==> A2{Authorized<br>?} A2 -- no --> L A2 == yes ==> H([Homepage]) H ==>E((End)) P -.-> E classDef red fill:#eee,stroke:#f00,color:#f00,stroke-width:1px; class H red; classDef orange fill:#eee,stroke:#aaa,color:#aaa,stroke-width:2px,stroke-dasharray:5,2 class P orange; classDef standard fill:#eee,stroke:#333,color:#000,stroke-width:1px; class S,A,A2,L,E standard;

This means the user will not see the requested page unless he/she clicks the link again (or copies the url into the browser's address bar).

AppGini Default

But this is not what we want at all. We'd like to redirect the user to the requested page after login, not to the homepage.


Expectation

What we want is, when the recipient clicks the link, his/her browser should open up and show the shared page after login.

graph LR S((Start)) ==> A{Authorized<br>?} A == no ==> L([Login]) L ==> A2{Authorized<br>?} A2 -- no --> L A2 == yes ==> P A -. yes .-> P([Requested Page]) P --> E((End)) classDef green fill:#fafafa,stroke:#0a0,color:#0a0,stroke-width:2px; class P green; classDef standard fill:#eee,stroke:#333,color:#000,stroke-width:1px; class S,A,A2,L,E standard;

Solution

Please note that this is BETA for testing purposes. Please provide feedback if this works for you or not.

We have done all the hard work for you and provide a simple solution:

Code

<!-- file: hooks/header-extras.php -->
<script>
  var common = new AppGiniCommon();
  common.autoRedirect();
</script>

That's all you have to do. Just call the autoRedirect() function on the AppGiniCommon object. Our library will do the rest.

Result

Wanna see it in action?


Pro-Tipp:

This integrates nicely with QR-Codes

Do you like it?