Jump to content

Redirect to same page after login {$smarty.server.HTTP_REFERER}


seog

Recommended Posts

Hello

 

I am trying redirect to same page after login but it always redirect me to last visited page.

 

I need to add the correct variable in value="{$smarty.server.HTTP_REFERER}"

 

<input type="hidden" class="hidden" name="back" value="{$smarty.server.HTTP_REFERER}" />
<input type="submit" id="SubmitLogin" name="SubmitLogin" class="signin_submit" value="{l s='Login'}"></input>
 
 
Example: When I am login in product page then the variable {$smarty.server.HTTP_REFERER} redirect me to previous visited page (category) instead to back to product page
 
Do you think what it could work adding the next referer codes before input login buttons?
{if $smarty.server.HTTP_REFERER == "http://www.mywebsite.com/index.php?controller=product"}
{if $smarty.server.HTTP_REFERER == "http://www.mywebsite.com/index.php?controller=category"}
{if $smarty.server.HTTP_REFERER == "http://www.mywebsite.com/index.php?controller=contact"}
{if $smarty.server.HTTP_REFERER == "http://www.mywebsite.com/index.php?controller=cms"}
Additional codes that maybe should be modified in controllers/front/AuthController.php
Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account'));
Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : $back));
 
Some suggestions?
 
Thank you very much
BR

 

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

Well the {$smarty.server.HTTP_REFERER} throws you to the referring page so this is the last visited one. You'll have to change that. I am not sure which php "variable" is available in Prestashop for this but I would assume something like PHP_SELF.

Link to comment
Share on other sites

  • 3 months later...

Hi,
 
i had the same situation, because i use the login form in a modal, so basically "HTTP_REFERER" wasnt the solution for me.
 
i have used:

<input type="hidden" class="hidden" name="back" value="{if isset($force_ssl) && $force_ssl}https://{else}http://{/if}{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}"/>
Edited by sooroos (see edit history)
Link to comment
Share on other sites

  • 10 months later...

Reply from @shniurs on other post..

 

Quote

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.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...