dt246813579 2015-09-11 06:18 采纳率: 0%
浏览 130
已采纳

current_url()返回错误的URL,如codeigniter中页眉中的favicon地址

I am trying to record the page details which the user is visiting and store them in the database. So, I wrote a function in a helper named hits_helper.php which uses the current_url() of codeigniter to do it.

function count_hits($options = array())
{
    $CI =& get_instance();

    $CI->load->library('user_agent');

    $date = date('Y-m-j H:i:s', strtotime(date('Y-m-j H:i:s')) + 1214);

    $data = array (

        'page_Address'  =>   current_url(),

        'hit_Date'      =>   $date

    );

    $CI->db->insert('counter', $data);

}

url helper is autoloaded.

It works and inserts the page url in the database, but it also inserts some urls like the favicon.ico and some css urls in the head section of the page respectively. What am I doing wrong?!

  • 写回答

2条回答 默认 最新

  • douwei8096 2015-09-11 06:51
    关注

    Create new helper name My_url_helper

    function current_url()
    {
    $CI =& get_instance();
    
    $url = $CI->config->site_url($CI->uri->uri_string());
    return $_SERVER['QUERY_STRING'] ? $url.'?'.$_SERVER['QUERY_STRING'] : $url;
    }
    

    May be it help you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)