Opencart Opecart-检查用户是否在特定页面上登录(是否为页面命令?)
我想确保只有特定用户才能访问我的网站内容,这取决于他们是否登录以及是否属于客户群。如果没有,我就用这个代码把他们踢出批发网站,踢进普通网站Opencart Opecart-检查用户是否在特定页面上登录(是否为页面命令?),opencart,Opencart,我想确保只有特定用户才能访问我的网站内容,这取决于他们是否登录以及是否属于客户群。如果没有,我就用这个代码把他们踢出批发网站,踢进普通网站 if ($logged && !$this->customer->getCustomerGroupId() == '1') { /*Check if logged in and belong to wholesale group*/ $this->customer->logout();
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');
但是他们会陷入重定向循环,因为登录页面的标题中有这个。除登录和注销页面外,我想在每个页面上检查这一点:
思考之后,我尝试使用此代码,但没有效果:
<?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中检查您是否在特定页面上的代码是什么?此信息不会传递给任何控制器。你能做的最好的就是你已经拥有的:
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
}
}
这看起来是一种更好的编程方式,但唯一的问题是如果我执行$page=$request->get['route'];不管我在哪一页,我什么也得不到。如果我使用$page以上的代码,页面总是返回为common/home。我使用搜索引擎优化网址。有没有更好的方法来获取路由?哦,显然应该是
$this->request->get['route']
。。。更新