Codeigniter用户登录后重定向到所需的url



我有一个网站Codeigniter 3框架。

有一个登录页面www.example.com/login

如果作者登录到面板,他们将重定向到主页www.example.com/author/feed。

作者控制器中有许多页面,如my-profile, edit-profile, reset-password等

如果作者想访问www.example.com/author/my-profile,他们被重定向到www.example.com/login,登录后他们被重定向到主页www.example.com/author/feed。

但是我希望他们重定向到www.example.com/author/my-profile。

我需要在我的代码中使用什么函数??

您可以使用辅助函数redirect(). 你可以在这里了解更多。

// after login
redirect('/author/my-profile');

在重定向到login页面之前,您需要将所需的route保存在session中:

$this->session->set_userdata('page', base_url('my-profile'));

用户登录时,可以查看page是否存储在session中,否则重定向到base url:

$pageLink = base_url();               
if ($this->session->userdata('page')) {
$pageLink = $this->session->userdata('page');
$this->session->unset_userdata('page');
}
redirect($pageLink);

最新更新