LiveEn
LiveEn

Reputation: 3253

Restrict controller/function access in muti user environment in opencart

I am doing some changes to my opencart site. in my case, its a multi-store

www.mywebsite.com - 1st store

store.mywebsite.com - 2nd store

What I want to do is restrict users of the first store from accessing

http://www.mywebsite.com/index.php?route=account/order

and if accessed redirect them to

http://store.mywebsite.com/index.php?route=account/order

or show an error so that account/order is only accessible through the sub-domain, http://store.mywebsite.com

I tried to add the below code as the constructor. But no luck

    public function __construct() {
        global $registry;
        parent::__construct($registry);

        if($_SERVER['HTTP_HOST'] == 'http://mywebsite.com' || $_SERVER['HTTP_HOST'] == 'http://www.mywebsite.com')
            {
            $this->url->redirect($this->url->link('http://store.mywebstore.com/index.php?route=account/order', '', 'SSL'));
            }

    }

can someone help me with this?

Upvotes: 0

Views: 114

Answers (1)

Jonid Bendo
Jonid Bendo

Reputation: 880

I shouldn't reccomend a redirect with .htaccess, opencart has this kind of actions by default, what i have used before is add this line of code in corresponding controller:

if($data['store_id'] != "destination_store_id"){
  $this->redirect($this->url->link('http://store.mywebstore.com/index.php?route=account/order', '', 'SSL'));    
}

this should work just fine, by my opinion.

Upvotes: 2

Related Questions