0

I've recently created a website using codeigniter so I can learn a php framework and I wonder how can I track the link that the people in my website is clicking to get out of my web.

Would be great to create a link like www.myweb.com/h1jkh13jk1h2 or some kind of unique string to that link and then store that in some statistics database.

Jotami
  • 3
  • 2

1 Answers1

0

I recommend to use Google Analytics to get details of different aspects of your users behaviour on your site.

But if you only want to log requests for specific pages/methods on your site you could create a method to insert data into a database table every time any method gets requested:

private function _log_activity($page='default_page'){
   $user_ip = $this->getUserIP(); 
   $sql = "INSERT INTO log_table (user_ip, page, request_date)
       VALUES($user_ip, $page, NOW())";
   $this->db->query($sql);
}

Copy the method getUserIP() in your controller from here: How to get Real IP from Visitor?

And usage in every method you want to track requests from:

$this->_log_activity('page_or_method_name');
Community
  • 1
  • 1
Michael Krikorev
  • 2,126
  • 1
  • 18
  • 25