8

In Joomla 3.5.1, I want to redirect users to the page they were before logging in.

If they login from mod_login, no problem, since the module is pending from the top menu, they just stay at that page.

The problem happens when the users login from the component: they are always redirected to the profile page.

In the menu item index.php?option=com_users&view=login there's an option to redirect users after login.

But how do I tell: "Get them back to the page they were before"?

Certain components are appending something like:

?return=L2YlQzMlQjNydW0tcGVyZ3VudGFzLWUtcmVzcG9zdGFzL2NvbnZlcnNhdGi9yZWFkLmh0bWw/aWQ9MjU=

To the URL, requesting a redirect to a specific page.

But they always go back to the profile page.

  • they always go back to the profile page. it happens to me, regardless of modifying as @Lodder suggested. – kokbira Nov 28 '17 at 14:23
7

Quite simple to do this.

You will firstly need to create a Template Override for the following file:

components/com_users/views/login/tmpl/default_login.php

Once done, open the following file (your override):

templates/MY_TEMPLATE/html/com_users/login/default_login.php

and go to line 81, where you will see the following code:

<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />

and replace it with:

<input type="hidden" name="return" value="<?php echo base64_encode($_SERVER['HTTP_REFERER']); ?>" />

Hope this helps

  • +1 Very nice idea. I'm not sure if the $_SERVER['HTTP_REFERER'] is always a valid choice, but I like the idea . – mavrosxristoforos Apr 12 '16 at 13:47
  • @mavrosxristoforos - Yeah it does have some drawbacks. A more advanced and reliable solution would involve a system plugin, making use of a session or cookie – Lodder Apr 12 '16 at 13:58
  • Thanks a lot for helping, I've been using template overrides for K2 for years but for core joomla it seems impossible. I did look at the instructions in your link, including the "Creating overrides" section but whatever changes I do are ignored. – Nuno Nogueira Apr 12 '16 at 14:14
  • @NunoNogueira - The file you open to make the changes to, does the path match what I've provided in my answer (2nd code snippet)? It should be exactly the same, apart from MY_TEMPLATE which of course is the name of your template – Lodder Apr 12 '16 at 14:15
  • @NunoNogueira - I made a mistake with the path, I've updated it now. (remove /view/) – Lodder Apr 12 '16 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.