How I make site statistics with codeigniter?

hello,
I will make the site statistics with codeigniter framework
how I can do it?
the statistics tell us:

  • how many visitor is connected now?
  • how many visitor connected this day?
  • how many visitor connected this week?
  • how many visitor connected this month?
  • how many visitor connected on site from begining?
    please help me

Hi promehdioh,

You would need to have a database associated with your codeigniter application.

In the database you might create a log table like (this is a MySQL example):


CREATE TABLE `logs` (

`VisID` int(10) unsigned NOT NULL auto_increment,

`VisIP` varchar(15) NOT NULL default '',

`VisRef` varchar(255) NOT NULL default '',

`VisUrl` varchar(255) NOT NULL default '',

`VisDate` datetime NOT NULL default '0000-00-00 00:00:00',

`VisAgent` varchar(255) NOT NULL default ''


PRIMARY KEY (`VisID`)

) TYPE=MyISAM ;

You don’t really need all these fields, so you could modify them if needed.

When a visitor comes to the site and I would assume logs-in then you would parse using PHP the following:

  • $HTTP_SERVER_VARS[‘REMOTE_ADDR’] - Gets the visitor’s IP.
  • $HTTP_SERVER_VARS[‘HTTP_REFERER’] - Gets the site that referred the user
  • $HTTP_SERVER_VARS[‘REQUEST_URI’] - The current page being visited
  • $HTTP_SERVER_VARS[‘HTTP_USER_AGENT’] - Gets info on the browser the user is using

[COLOR=#000000]
You would then insert a new visitor log entry in the logs table in the Database.

You would also need to write a number of reports that would select the statistics you need. You would write a Visitors by Day, Visitors per Week, and Visitors by Month functions in PHP that would run SELECT statements that could return the appropriate number for for each report.

After running each report your application would need to present this data as HTML/CSS. You could use AJAX to have this auto update or call for the display functions when a user first logs in.

The ‘Who is currently logged in’ is a little different. You could have a is_logged_in field in your user database table and could search for all users where this is set to 1 (they are logged in). Remember some people don’t log out so this is not highly accurate, but is a simple way.

You would need to trim the logs table after each month and somewhere you could keep a visitor total field where you keep a running total of just the total number of visitors.

Hope this gives you a starting point.

Regards,
Steve
[/COLOR]