Welcome Guest, Not a member yet? Register   Sign In
A very simple tracker
#1

[eluser]igniteflow[/eluser]
As the title says I've made a very simple tracker more as a learning exercise than anything else. I'm new to CI and would appreciate some constructive criticism as to how I'm implementing this and if it follows best practices. Here's the code:

I made a simple tracker, thought I'd post it here as it might be useful as a starting block or for people who don't need a fully featured version. I'm new to CI, so please point out any errors/bad practices, I'd appreciate it...

SQL

Code:
CREATE TABLE IF NOT EXISTS `tracker` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ip` varchar(20) NOT NULL,
  `browser` varchar(500) NOT NULL,
  `url` varchar(500) NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;


I put this at the end of _footer.php which I call in the VIEW

Code:
<?php
  $tracker['id'] = '';
  $tracker['ip'] = $this->input->ip_address();
  $tracker['browser'] = $this->input->user_agent();
  $tracker['url'] = $_SERVER['REQUEST_URI'];
  
  // insert data to db      
  $this->db->insert('tracker', $tracker);
?>

Is putting this code in the view file in this way appropriate or should it be somewhere else?
#2

[eluser]Craig300[/eluser]
Hi,

It's a nice idea, however, this may slow the system down. Which is why google analytics will probably be better than creating on-site stats. This idea may be useful for other types of tracking but for pages views, I would rather use google analytics.

Craig
#3

[eluser]textnotspeech[/eluser]
I tend to agree with Craig300 although I would suggest putting this code in the controller. My rule of thumb is only control structures that manipulate display go in the view (ie. foreach and simple if else blocks).
#4

[eluser]Jay Logan[/eluser]
I do something similar to this and my database table was 140 MB now after about 5 months. So what I recently did was filter out the hits based on the date and whether or not the user submitted a form. I just use AWStats if I really need to look at old stats.




Theme © iAndrew 2016 - Forum software by © MyBB