Page 1 of 1
Force visitor to register/login
Posted: Thu Jul 16, 2009 5:47 am
by hyperjase
Hi guys,
Is there any way to force visitors to either register or login to view the site? I have a little knowledge of PHP and know that it can be done via sessions? I'm just not sure how abouts to go about achieving this.
Thanks,
HJ
Re: Force visitor to register/login
Posted: Thu Jul 16, 2009 8:59 am
by make-oc
This is a quick way which works for me…
Put this in line 1 of your layout.tpl (view/theme/default/template/common/layout.tpl)
Code: Select all
<?php
if (!$this->customer->isLogged()
&& $this->url->http('account/login') != $breadcrumbs[1]['href']) {
$this->redirect($this->url->https('account/login'));
}
?>
Cheers
Re: Force visitor to register/login
Posted: Thu Jul 16, 2009 5:47 pm
by hyperjase
Thanks for getting back to me, I've added the code and now end up with a redirect loop in FF:
Redirection limit for this URL exceeded. Unable to load the requested page. This may be caused by cookies that are blocked.
I'm not fully clued up on PHP so aren't sure whats going on here.
Thanks for your help,
HJ
Re: Force visitor to register/login
Posted: Fri Jul 17, 2009 7:40 am
by make-oc
Can you post your layout.tpl code please.
A loop should not be created, as the code breaks when
Code: Select all
$this->url->http('account/login') == $breadcrumbs[1]['href']
or check whether changing from
Code: Select all
$this->redirect($this->url->https('account/login'))
to (just 'http')
Code: Select all
$this->redirect($this->url->http('account/login'))
makes a difference…
Re: Force visitor to register/login
Posted: Sat Jul 18, 2009 12:36 am
by tronics
You need:
Code: Select all
<?php
if (!$this->customer->isLogged()
&& $this->url->http('account/login') != $breadcrumbs[2]['href']) {
$this->redirect($this->url->https('account/login'));
}
?>
Regards tronics
Re: Force visitor to register/login
Posted: Sat Jul 18, 2009 12:41 am
by tronics
Even better:
Code: Select all
if (!$this->customer->isLogged() &&
(
$this->url->http('account/login') != $breadcrumbs[2]['href']
&& $this->url->http('account/forgotten') != $breadcrumbs[2]['href']
&& $this->url->http('account/create') != $breadcrumbs[2]['href']
)
) {
$this->redirect($this->url->http('account/login'));
}
Re: Force visitor to register/login
Posted: Sat Jul 18, 2009 3:45 am
by hyperjase
tronics wrote:Even better:
Code: Select all
if (!$this->customer->isLogged() &&
(
$this->url->http('account/login') != $breadcrumbs[2]['href']
&& $this->url->http('account/forgotten') != $breadcrumbs[2]['href']
&& $this->url->http('account/create') != $breadcrumbs[2]['href']
)
) {
$this->redirect($this->url->http('account/login'));
}
I did try removing the "s" from the https first off, but that had no effect, but the above code works perfectly.
Thanks so much!
Just one final thing, after login/registration is there a way of forwarding to the homepage (catalog) rather than the account page?
Thanks once again,
HJ
Re: Force visitor to register/login
Posted: Sat Jul 18, 2009 5:42 pm
by iloveopencart
after login/registration is there a way of forwarding to the homepage (catalog) rather than the account page?
Easy

. Open
catalog/controller/account/login.php and change line 18:
$this->redirect($this->url->https('account/account')); to:
Code: Select all
$this->redirect($this->url->https('common/home'));
That takes care of the login. For new users who just created an account, open
catalog/controller/account/success.php and change line 41:
$this->data['continue'] = $this->url->http('account/account'); to:
Code: Select all
$this->data['continue'] = $this->url->http('common/home');
Re: Force visitor to register/login
Posted: Mon Jul 20, 2009 3:31 am
by hyperjase
Perfect! Thanks so much guys, that did the trick, got it working a-ok now.
Thanks once again,
HJ
Re: Force visitor to register/login
Posted: Tue Jul 21, 2009 8:03 am
by drbyday
Wow Thanks guys! One more thing. Is it possible to hide all the side column as well (categories, brands, shopping cart etc) if the customer is not logged in?
Re: Force visitor to register/login
Posted: Tue Jul 21, 2009 10:20 pm
by iloveopencart
Is it possible to hide all the side column as well (categories, brands, shopping cart etc) if the customer is not logged in?
It is! In the template file for each module, make the very first line:
Code: Select all
<?php if ($this->customer->isLogged()) { ?>
and the very last line:
That's it.
Re: Force visitor to register/login
Posted: Wed Feb 03, 2010 1:07 am
by gila
hello, i used your solution, it works perfectly!!!
just one thing, i can't to open the privacy windows
i added this string
Code: Select all
&& $this->url->http('information/information') != $breadcrumbs[2]['href']
but it do not work, how can i do?
thanks
Redirect after Login
Posted: Sun Apr 11, 2010 6:39 pm
by marogiannis
Hello,
I am looking for a solution for v1.4.6 and up where the user, after registering or login to his account, he is then redirected to a specific page of my choice. For example, a redirection to index.php?route=product/category&path=134
I followed instructions here (based on older OC versions - so I wasnt able to fix this)...
I did some testing and I encountered I some problems after making some changes to the files catalog/controller/account/login.php and catalog/controller/account/success.php.
Obviously, I made some mistakes when changing the script.
I would appreciate some help on this matter.
Thank you
Giannis
Re: Redirect after Login
Posted: Mon Jun 06, 2011 6:50 am
by bobpour
I try to find "view/theme/default/template/common/layout.tpl" but can't find it!
I think things have been changed since 1.4... I am running 1.5.02 can someone tell me what file i need to look for? is it still under layout.tpl or...