Post by hyperjase » Thu Jul 16, 2009 5:47 am

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

Newbie

Posts

Joined
Sun Jul 05, 2009 8:39 am

Post by make-oc » Thu Jul 16, 2009 8:59 am

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

New member

Posts

Joined
Tue Apr 07, 2009 2:17 pm

Post by hyperjase » Thu Jul 16, 2009 5:47 pm

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

Newbie

Posts

Joined
Sun Jul 05, 2009 8:39 am

Post by make-oc » Fri Jul 17, 2009 7:40 am

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…

New member

Posts

Joined
Tue Apr 07, 2009 2:17 pm

Post by tronics » Sat Jul 18, 2009 12:36 am

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

Newbie

Posts

Joined
Wed Jul 15, 2009 5:05 pm

Post by tronics » Sat Jul 18, 2009 12:41 am

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'));
}

Newbie

Posts

Joined
Wed Jul 15, 2009 5:05 pm

Post by hyperjase » Sat Jul 18, 2009 3:45 am

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

Newbie

Posts

Joined
Sun Jul 05, 2009 8:39 am

Post by iloveopencart » Sat Jul 18, 2009 5:42 pm

after login/registration is there a way of forwarding to the homepage (catalog) rather than the account page?
Easy ;D. 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');

User avatar
Global Moderator

Posts

Joined
Thu Mar 05, 2009 11:15 pm
Location - Phoenix, AZ

Post by hyperjase » Mon Jul 20, 2009 3:31 am

Perfect! Thanks so much guys, that did the trick, got it working a-ok now.

Thanks once again,

HJ

Newbie

Posts

Joined
Sun Jul 05, 2009 8:39 am

Post by drbyday » Tue Jul 21, 2009 8:03 am

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?

Newbie

Posts

Joined
Tue Jul 21, 2009 8:02 am

Post by iloveopencart » Tue Jul 21, 2009 10:20 pm

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:

Code: Select all

<?php } ?>
That's it.

User avatar
Global Moderator

Posts

Joined
Thu Mar 05, 2009 11:15 pm
Location - Phoenix, AZ

Post by gila » Wed Feb 03, 2010 1:07 am

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

New member

Posts

Joined
Fri Jan 25, 2008 4:33 am

Post by marogiannis » Sun Apr 11, 2010 6:39 pm

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
Last edited by i2Paq on Sun Apr 11, 2010 6:40 pm, edited 1 time in total.
Reason: Merged

GxG Web Design Greece
Κατασκευή Ιστοσελίδων
Βελτιστοποίηση Ιστοσελίδων


Newbie

Posts

Joined
Thu Jan 28, 2010 3:18 am


Post by bobpour » Mon Jun 06, 2011 6:50 am

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...

Newbie

Posts

Joined
Sun Jun 05, 2011 1:00 am
Who is online

Users browsing this forum: Google [Bot] and 61 guests