2014-02-12 16 views
0

我正在對opencart網站進行一些更改。於我而言,它是一個多店在opencart的多用戶環境中限制控制器/函數訪問

www.mywebsite.com - 第一店

store.mywebsite.com - 2店

我想要做的是限制用戶訪問

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

所述第一存儲

如果訪問重定向到

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

或顯示錯誤,使account/order只有通過子域名訪問,http://store.mywebsite.com

我嘗試添加以下代碼構造函數。但沒有運氣

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

    } 

有人可以幫助我嗎?

+0

這應該更好地通過'.htaccess'重定向規則來實現,你不覺得嗎? – shadyyx

回答

2

我不應該reccomend用的.htaccess重定向,Opencart的有這種默認的行爲,我以前使用的是添加這行代碼在相應的控制器:

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

這應該只是工作好,我認爲。

+0

啊..我差點忘了商店ID。非常感謝! – LiveEn

+0

很高興我能幫忙:) –