重定向到codeigniter中的引荐来源网址 [英] Redirect to referer url in codeigniter

查看:74
本文介绍了重定向到codeigniter中的引荐来源网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我项目的消息传递系统中,当您从用户那里收到消息时,您会收到一封电子邮件警报,提示另一个用户已经发送了一条消息以查看消息,请单击此处(即消息的URL),因此,如果用户未登录进入系统后,他将重定向到登录页面,登录后应返回到引荐来源网址。我已经在核心文件夹中创建了一个basecontoller,并扩展了CI_controller,身份验证代码如下。

In messaging system of my project when you get a message from a user you a email alert saying that the another user has sent a message to view the message click here (i.e the url of message) So if the user is not logged in to system he gets redirect to login page and after login it should get back to the referer url. I have made a basecontoller in core folder and extending the CI_controller the authenticating code is as follows.

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部分。

The referer url is "http://example.com/project/pm/view_conversation?id=11" now the problem is I am getting referer url till view_conversation and not able to get the id part.

有任何建议吗?

谢谢。

推荐答案

这可以帮助:

CI 2+
https://www.codeigniter.com/userguide2/libraries/user_agent.html

CI 3+
http://www.codeigniter.com/userguide3/libraries/user_agent.html

以下解决方案适用于Codeigniter版本3

Below solution is for Codeigniter version 3

$this->load->library('user_agent');
if ($this->agent->is_referral())
{
    echo $this->agent->referrer();
}

这篇关于重定向到codeigniter中的引荐来源网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆