1
我想確保只有特定用戶才能根據他們是否已登錄並且是否屬於客戶組訪問我的網站內容。如果沒有,我使用此代碼將他們踢出批發網站並進入常規網站。Opecart - 檢查用戶是否在特定頁面(is_page命令?)
if ($logged && !$this->customer->getCustomerGroupId() == '1') { /*Check if logged in and belong to wholesale group*/
$this->customer->logout();
$this->redirect("https://example.com/");
}
問題是,如果他們沒有登錄並找到他們仍然可以瀏覽網站的方式。我想一個方法來檢查自己是否登錄我嘗試使用這樣的:
if (!$logged) { /*Check if user is logged in, not = redirect to login page*/
$this->redirect('https://wholesale.garrysun.com/index.php?route=account/login');
但他們會卡在重定向循環,因爲登錄頁面有這個在標題中。我想檢查此每一頁上除了登錄和註銷頁面:
http://example.com/index.php?route=account/login
http://example.com/index.php?route=account/logout
考慮這件事後,我嘗試使用此代碼,但無濟於事:
<?php
/*Check if on wholesale site*/
if($this->config->get('config_store_id') == 1) {
/*Check if user is logged in, if not and not on login/logout/register page = redirect to login page*/
if(!$logged){
if(!$this->request->get['route'] == 'account/login' || !$this->request->get['route'] == 'account/logout' || !$this->request->get['route'] == 'account/register'){
$this->redirect('https://wholesale.garrysun.com/index.php?route=account/login');
}
}else if($logged && !$this->customer->getCustomerGroupId() == '1') { /* User is logged in and not a wholesale customer */
$this->customer->logout();
$this->redirect("https://garrysun.com/");
}
}
?>
opencart中的代碼用於檢查您是否在特定頁面上?
這看起來像一個更好的方式來編程,但唯一的問題是,如果我做$ page = $ request-> get ['route']] ;無論我在哪個頁面,我都沒有得到任何東西。如果我使用$頁面上面的代碼,總是會回到普通/主頁。我正在使用SEO網址。有沒有更好的方法來獲得路線? – MattM
哎呀,它顯然應該是'$ this-> request-> get ['route']'... updated – rjdown