如果客户未从网站上的任何页面登录,我希望将客户重定向到登录页面。我正在尝试将对子域的访问限制为特定客户组,并且我的代码的其余部分可以正常工作。
如果我在 home.tpl 上使用以下代码,它就可以工作
if (!$logged) {
$this->redirect($this->url->link('account/login', '', 'SSL'));
}
但是如果我把它放在标题中(这样它会对每个页面使用react),我会得到一个重定向循环,因为它会尝试将实际的登录页面重定向到自身。
有没有一种正确的表达方式:
if ($this->url->link != 'account/login') {
$this->redirect($this->url->link('account/login', '', 'SSL'));
}
预先感谢您的帮助。
马特
最佳答案
假设您想检查商店是否也是子域,您应该使用类似这样的代码
// Check store ID against subdomain store id value
if($this->config->get('config_store_id') == 123) {
// Check customer isn't logged in
if(!$this->customer->isLogged()) {
// Redirect if route isn't account/login
if(empty($this->request->get['route']) || $this->request->get['route'] != 'account/login') {
$this->redirect($this->url->link('account/login', '', 'SSL'));
}
}
}
关于redirect - Opencart 强制登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20357962/