Jump to content

[Solved] When user logins redirect to same page


Recommended Posts

I need to redirect user to the same page where he filled log-in details.

 

I have a custom pop-up login form which posts to mywebsite.com/login page (the login form can be accessed in any page).

The problem is that when I use ?back=mypage in form post url, user is still redirected to my-acount.

 

I found that these values are set in AuthController.php in this line:

if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back))
                        Tools::redirect(html_entity_decode($back));
                    Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account'));

It seems that posting to url with ?back=ur_to_redirect should work.
I also tried to create an input field (name=back) with url in value, but it didn't worked as well.

 

I use PrestaShop 1.5.6.1

 

Any thoughts how can I get user redirect to previous page after login?

Edited by shniurs (see edit history)
Link to comment
Share on other sites

Been looking for the solution whole day, after I posted this post it took me few minutes to figure this out.

 

The solution:

 

find this code in AuthController.php

if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back))
	Tools::redirect(html_entity_decode($back));
	Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account'));

Replace it with this code:

if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back))
	Tools::redirect(html_entity_decode($back));
	Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);

It will redirect you to the same page where login form was submitted.

  • Like 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...