Opencart - 检查用户是否在特定页面上(is_page命令?)

时间:2014-11-14 00:49:24

标签: opencart

我想确保只有特定用户才能访问我的网站内容,具体取决于他们是否已登录并且是客户群的一部分。如果没有,我会使用此代码将它们从批发站点踢出并进入常规站点。

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中的代码是什么来检查您是否在特定页面上?

1 个答案:

答案 0 :(得分:1)

此信息不会传递给任何控制器。你能做的最好的就是你已经拥有的东西:

if (isset($this->request->get['route'])) {
    $page = $this->request->get['route'];
} else {
    $page = 'common/home';
}

if ($this->config->get('config_store_id') == 1) {
    if (!$this->customer->isLogged() && !in_array($page, array('account/login', 'account/logout', 'account/register'))) {
        ... redirect
    }
}