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