显示仅登录的信息页面和特定客户组

时间:2013-12-14 05:11:00

标签: php redirect login opencart restrict

我在stackoverflow上找到了以下代码,它只能访问登录客户的信息页面,这非常有用。我想要一个增强功能。信息页面只能由特定客户组访问。

if (isset($this->request->get['information_id']) && $this->request->get['information_id'] == '{ID}') 
{
    //If the information_id is provided and it matches the ID you wish to protect
    if (!$this->customer->isLogged()) {
        //If the customer is not logged in already, redirect them to the login page
        //Use $this->session->data['redirect'] to redirect them back to this page after logging in
        $this->session->data['redirect'] = $this->url->link('information/information', 'information_id=' . $this->request->get['information_id']);
        //Do the redirect
        $this->redirect($this->url->link('account/login', '', 'SSL'));
    }
}

代码来源:Is it possible to require a login for an OpenCart Information page, and ONLY the information page?

1 个答案:

答案 0 :(得分:0)

更新您的第二个if条件,如下所示:

if (isset($this->request->get['information_id']) && $this->request->get['information_id'] == '{ID}') {

    if (!$this->customer->isLogged() || $this->customer->getCustomerGroupId()  != 1) { //where '1' is your customer groupid for which you want to give access.. 

        $this->session->data['redirect'] = $this->url->link('information/information', 'information_id=' . $this->request->get['information_id']);
        $this->redirect($this->url->link('account/login', '', 'SSL'));
    }
}

$this->customer->getCustomerGroupId() - 返回您的客户群ID。

度过愉快的一天:) !!