AnilaN Posted May 25, 2011 Share Posted May 25, 2011 Hi, For my website I've hidden the prices and user has to log in to see them. So I redirect user to authentication page. What I want to do is redirect the user, after log in or creating an account, to the original page (from where he was redirected to the authentication page). As i have hidden the prices everywhere, there are many places that allow user to go to the authentication page so i can't set a fixed url.I'd really appreciate some help.Thanks in advance.Aany 1 Link to comment Share on other sites More sharing options...
noesac Posted May 25, 2011 Share Posted May 25, 2011 Good idea, hopefully someone has a suggestion! Link to comment Share on other sites More sharing options...
shokinro Posted May 25, 2011 Share Posted May 25, 2011 when you redirect user to authentication page, put parameters to the URLafter authentication, use this parameter redirect user back to the page.by default, there is parameter back is available to use. You can do this for simple pages.but if your return page itself require parameters, you will need to find a way keep all parameters.for example, you BASE64 encoding the return URL and then decode it when redirect user back. just a thought, never tested, but I think it should doable. Link to comment Share on other sites More sharing options...
AnilaN Posted May 26, 2011 Author Share Posted May 26, 2011 Hi thanks for your suggestion. I'll see if i can use it properly (because I just started web programming and there are a lot of thing i'm still learning). I have another question: Once the user is redirected to the authentication page and he clicks on 'log in'. Can i send him back to the previuos page? I think I have to modify in authController.php the following line: Tools::redirect('my-account.php');But the problem is i don't know what to put in it.I have tried to put '$back' but it takes me to the home page instead of previous.Can someone please help me fix this.Thanks Link to comment Share on other sites More sharing options...
AnilaN Posted June 1, 2011 Author Share Posted June 1, 2011 I tried using $_SERVER['HTTP_REFERER']; which is supposed to redirect to previous page but it doesn't work. I use it when user clicks on 'log in' to send him back but when user clicks on it he logs in but stays on authentication.php.Is it normal or I have become the main target of every problem (whether it exists or not :s)?. Link to comment Share on other sites More sharing options...
Luizsb Posted November 25, 2011 Share Posted November 25, 2011 Hi guys, I've been searching for this solution long time... Did someone solved it? I'd like to redirect the user to the previous page. My problem is... When the customer comes from a product page (id_product=N) and he's not logged, he goes to authentication. But after his login I'd like to redirect to the product page (id_product=N) where he cames from. I've already changed the ProductController.php, inserting: public $auth = true; public $authRedirection = 'product.php'; But the customer is redirected to the product page without id_product and shows a error. Could someone help me? Thanks in advance! Link to comment Share on other sites More sharing options...
Luizsb Posted November 25, 2011 Share Posted November 25, 2011 Hi guys, I found the solution. I don't know if this is the best way, but it's working pretty good! I've changed 2 files. STEP 1 - FrontController.php Where you find this: if ($this->auth AND !$cookie->isLogged($this->guestAllowed)){ Tools::redirect('authentication.php'.($this->authRedirection ? '?back='.$this->authRedirection : '')); } change for: if ($this->auth AND !$cookie->isLogged($this->guestAllowed)){ if ($this->authRedirection === 'back') { $this->authRedirection = Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])); } Tools::redirect('authentication.php'.($this->authRedirection ? '?back='.$this->authRedirection : '')); } The conditional ($this->authRedirection === 'back') will be used in the ProductController.php or wherever you want. STEP 2 - ProductController.php I put new public var to the Class public $auth = true; public $authRedirection = 'back'; When you do that, every time when the user is not logged, he will be redirect to Autentication, so he need to log in and then he will be redirect to the previous page. I've made just for the Product, but you can do for the Category, and everything else. You just need to do the 2nd Step again. I hope I helped! If you have a better solution, please write back! 1 Link to comment Share on other sites More sharing options...
Guest Posted November 26, 2011 Share Posted November 26, 2011 How i can lsend letter for yor ? Link to comment Share on other sites More sharing options...
cyjambo Posted November 27, 2011 Share Posted November 27, 2011 Hi guys, I found the solution. I don't know if this is the best way, but it's working pretty good! I've changed 2 files. STEP 1 - FrontController.php Where you find this: if ($this->auth AND !$cookie->isLogged($this->guestAllowed)){ Tools::redirect('authentication.php'.($this->authRedirection ? '?back='.$this->authRedirection : '')); } change for: if ($this->auth AND !$cookie->isLogged($this->guestAllowed)){ if ($this->authRedirection === 'back') { $this->authRedirection = Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])); } Tools::redirect('authentication.php'.($this->authRedirection ? '?back='.$this->authRedirection : '')); } The conditional ($this->authRedirection === 'back') will be used in the ProductController.php or wherever you want. STEP 2 - ProductController.php I put new public var to the Class public $auth = true; public $authRedirection = 'back'; When you do that, every time when the user is not logged, he will be redirect to Autentication, so he need to log in and then he will be redirect to the previous page. I've made just for the Product, but you can do for the Category, and everything else. You just need to do the 2nd Step again. I hope I helped! If you have a better solution, please write back! Hi Luizsb, Thanks for posting this, this works fine if you only have registered users, or you want the users to log in or register before seeing products. But unfortunately in my case I would like everyone to see everything all the time. I also have guest checkout enabled. So in my case I would only need the login page to redirect to the previous page (which can be a product page, category page, about me page, sitemap, it doesn't really matter what to be honest...). Since the only way to go to the login page is by clicking the blockuserinfo Login button, is there a way to make this work so it just simply goes back to the previous page? I hope you understand what I mean By the way, yours is a good solution for a shop where you need everyone to register and the products or categories should only be seen by registered users. But this is not the case with my shop... Thanks a lot for your efforts!!! Peace! 1 Link to comment Share on other sites More sharing options...
happy Posted April 21, 2013 Share Posted April 21, 2013 hello, Seems like you guys already found out how to redirect users to the authentication page when he tries to click on a member only menu bar. My websites brings users to an error page instead of the authentication page. If you can tell me how to redirect user to authentication page I will be grateful. Thank you. RESPOND ASAP PLEASE Link to comment Share on other sites More sharing options...
legionari86 Posted April 5, 2014 Share Posted April 5, 2014 Hello everyone, I have two links in the header having a MultiShop I need to address the Customer in the main home, the Business (url created by me) must be addressed to the subfolder / shop but can not find where to put the url. Both links take me back now always in authentication? Back = my-account # account-creation I wish that one of these two go up / shop / authentication? Back = my-account # account-creation It 'can help? Link to comment Share on other sites More sharing options...
legionari86 Posted April 5, 2014 Share Posted April 5, 2014 Ciao a tutti, ho due link nell'intestazione avere un MultiShop ho bisogno di affrontare il Cliente nella casa principale, la Business (url creato da me) deve essere indirizzata al sottocartella / negozio ma non riesce a trovare dove mettere l'url. Entrambi i link mi portano indietro sempre di autenticazione? Indietro = my-conto # considerazione la creazione di Vorrei che uno di questi due salgono / shop / autenticazione? Indietro = my-conto # considerazione la creazione di E 'possibile aiutare? Hello everyone, I have two links in the header having a MultiShop I need to address the Customer in the main home, the Business (url created by me) must be addressed to the subfolder / shop but can not find where to put the url. Both links take me back now always in authentication? Back = my-account # account-creation I wish that one of these two go up / shop / authentication? Back = my-account # account-creation It 'can help? Link to comment Share on other sites More sharing options...
vekia Posted April 5, 2014 Share Posted April 5, 2014 let's clarify. Customer -> redirects to authentication page Busines -> redirects... where? Link to comment Share on other sites More sharing options...
legionari86 Posted April 5, 2014 Share Posted April 5, 2014 Hi, business redirect to virtual subfolder multishop, root/shop Customer is: www.*******.it/authentication? Back = my-account Business is: www.******.it/shopbusiness/authentication? Back = my-account possibile? in the address bar if I insert the url work Link to comment Share on other sites More sharing options...
legionari86 Posted April 5, 2014 Share Posted April 5, 2014 Hi, business redirect to virtual subfolder multishop, root/shop Customer is: www.*******.it/authentication? Back = my-account.php Business is: www.******.it/shopbusiness/authentication? Back = my-account.pjp possibile? in the address bar if I insert the url work Link to comment Share on other sites More sharing options...
legionari86 Posted April 5, 2014 Share Posted April 5, 2014 I can post the link of the multi store? So you can explain better? Sorry for my english Link to comment Share on other sites More sharing options...
legionari86 Posted April 5, 2014 Share Posted April 5, 2014 I wish I could create two simple links in the header under the key empty cart. One that directs to account authentication, the other to point to subfolder / shop authentication account! Anything else Link to comment Share on other sites More sharing options...
vekia Posted April 5, 2014 Share Posted April 5, 2014 so, in your subdirectory: /shopbusiness/ you've got other shop based on multistore feature? you can't redirect user to other shop(/shopbusiness) if he logged in "/" shop Link to comment Share on other sites More sharing options...
legionari86 Posted April 5, 2014 Share Posted April 5, 2014 How can I do? Create two links in the header and insert the url Link to comment Share on other sites More sharing options...
legionari86 Posted April 5, 2014 Share Posted April 5, 2014 How can I do? Create two links in the header and insert the url Link to comment Share on other sites More sharing options...
legionari86 Posted April 5, 2014 Share Posted April 5, 2014 I have created a new group shop and new shop to option back office.. Link to comment Share on other sites More sharing options...
vekia Posted April 5, 2014 Share Posted April 5, 2014 im confused a little. you want to just add links? nothing more? i just thought that you want to redirect user as topic title stated. Link to comment Share on other sites More sharing options...
legionari86 Posted April 6, 2014 Share Posted April 6, 2014 (edited) At this point if you do not find the solution, perhaps the only thing possible is to create 2 links in the header do you think? I take a help? the site is this http://www.ceramicaloddo.it/ As you can see I created two entries under the carriage, but I can not redirect where I want. Try also the site / shopbusiness on / shopbusiness the virtual shop you may notice that the prices are different because I manage them separately, but I need the user to go directly to Vat / shopbusiness Edited April 6, 2014 by legionari86 (see edit history) Link to comment Share on other sites More sharing options...
legionari86 Posted April 7, 2014 Share Posted April 7, 2014 I solved it by yourself, looking good I deleted the code <a href="{$link-> getPageLink ('my-account', true)} " overwriting with this <a href = "authentication? back = my-account" <a href = "shopbusiness / authentication? back = my-account" Login button now address two different authentication pages Link to comment Share on other sites More sharing options...
maitmansour95 Posted April 21, 2017 Share Posted April 21, 2017 (edited) Hello, this is my example to redirect user to a product page (where he was) after authentification : in AuthController you use the init function, before doing anything get the previous URL with $_SERVER['HTTP_REFERER'] i get the product number then i save the new url into $_GET['back'] EXAMPLE : $_GET['back']="product&id_product=".$id; After this, you have two things to get : if your URL includes (&) like me, you need to change this in Tools::redirect else, anything will work fine So in my case, i went to Tools::Redirect, and add this lines just before header('Location: '.$url); exit;: $url=str_replace("?amp;","&",$url); header('Location: '.$url); exit; Taraaaaaa PS : excuse my english... Edited April 21, 2017 by maitmansour95 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts