在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?

我正在对我的opencart网站进行一些更改。 在我的情况下,它是一个多商店 p>

www.mywebsite.com - 第一家商店 p>

store.mywebsite.com - 第二家商店 p> blockquote>

我想要做的是限制第一家商店的用户访问 p>

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

如果被访问,将它们重定向到 p>

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

或显示错误,以便 account / order code>只能通过子域访问, http://store.mywebsite.com code> p>

我尝试添加以下代码作为构造函数。 但没有运气 p>

  public function __construct(){
 global $ registry; 
 parent :: __ construct($ registry); 
 
 if($ _ SERVER ['  HTTP_HOST'] =='http://mywebsite.com'|| $ _SERVER ['HTTP_HOST'] =='http://www.mywebsite.com')
 {
 $ this-> url-&gt  ;重定向($ this-> url-> link('http://store.mywebstore.com/index.php?route=account/order','','SSL')); 
} 
  
} 
  code>  pre> 
 
 

有人可以帮我解决这个问题吗? p> div>

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.