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条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化