在我的项目的消息传递系统中,当您收到用户发来的消息时,您会收到一封电子邮件警报,说另一个用户已发送消息以查看该消息,请单击此处(即消息的网址)因此,如果用户未登录系统他被重定向到登录页面,登录后应该返回到引用网址。我在核心文件夹中创建了一个basecontoller,并扩展了CI_controller,验证代码如下。
function authenticate($type = 'user')
{
if($type == 'user')
{
if($this->user_id)
{
// user is logged in. check for permissions now
}
else
{
// user isnt logged in. store the referrer URL in a var.
if(isset($_SERVER['HTTP_REFERER']))
{
$redirect_to = str_replace(base_url(),'',$_SERVER['HTTP_REFERER']);
}
else
{
$redirect_to = $this->uri->uri_string();
}
redirect('user/login?redirect='.$redirect_to);
exit;
}
}
if($type == 'admin')
{
if($this->session->userdata('admin_id') && $this->session->userdata('user_type') ==5)
{
// Admin is logged in
}
else
{
redirect('admin/login');
exit;
}
}
}
引用网址为“http://example.com/project/pm/view_conversation?id=11”
现在的问题是我在 view_conversation 之前获取引用网址,但无法获取 id 部分。
有什么建议吗?
谢谢。
这可以帮助:
CI 2+
https://www.codeigniter.com/userguide2/libraries/user_agent.html https://www.codeigniter.com/userguide2/libraries/user_agent.html
CI 3+
http://www.codeigniter.com/userguide3/libraries/user_agent.html http://www.codeigniter.com/userguide3/libraries/user_agent.html
以下解决方案适用于 Codeigniter 版本 3
$this->load->library('user_agent');
if ($this->agent->is_referral())
{
echo $this->agent->referrer();
}
更新:有关如何使用相同的 user_agent 库获取引荐来源网址信息的有趣且有用的信息
https://www.tutorialandexample.com/user-agent-class/ https://www.tutorialandexample.com/user-agent-class/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)