[英]Opencart 2.2 : Redirect user to same page after login
In Opencart, I am unable to do that after login the user go to the previous page on which the user is, rather than the account page.在 Opencart 中,我无法在用户登录后转到用户所在的上一页,而不是帐户页面。 I am not interested to use any extension for it.
我没有兴趣使用任何扩展名。
You should pass current URL along with your login form your current URL will be like this :您应该将当前 URL 与登录表单一起传递,您当前的 URL 将如下所示:
<?php
$url = "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
?>
pass it in a hidden field of a form ,将其传递到表单的隐藏字段中,
<input type="hidden" name="redirect" value="<?php echo $url; ?>" >
After successful login redirect to this URL成功登录后重定向到此 URL
$this->response->redirect($_POST['redirect']);
Open catalog/controller/account/login.php file打开目录/控制器/帐户/login.php 文件
find for this为此找到
if ($this->customer->isLogged()) {
$this->redirect($this->url->link('account/account', '', 'SSL'));
}
replace it by将其替换为
if ($this->customer->isLogged()) {
$this->redirect($this->url->link('account/account', '', 'SSL'));
}elseif(!isset($this->session->data['redirect']) && isset($_SERVER['HTTP_REFERER'])){
$this->session->data['redirect'] = $_SERVER['HTTP_REFERER'];
}
Hope the answer for the question希望问题的答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.