dornc9470 2012-07-07 11:52
浏览 58
已采纳

在codeigniter中重定向到引用URL

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;
            }
        }
    }

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.

Any suggestion ?

Thank you.

  • 写回答

5条回答 默认 最新

  • dqd3690 2013-04-13 18:15
    关注

    This can help:

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

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

    $this->load->library('user_agent');
    if ($this->agent->is_referral())
    {
        echo $this->agent->referrer();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!