Codeigniter Online Visitor Tracking System

Every website owner would like to know the progress to the count of the online visitors because it gives them overall idea on the website’s analytical measurements. It will also give them how to make improvements on the websites. This example will give you an idea how to implement such system to track visitors who visit your website on daily basis. This example also shows how to use hooks in Codeigniter framework. You may also look into another tutorial how to use hooks Display site maintenence message using Codeigniter

Prerequisites

Netbeans 8.1
XAMPP in Windows
Codeigniter 3.0.6

Configure XAMPP and Netbeans

From Netbeans IDE go to Tools->Options. Click on PHP. Now on tab “General” browse the file for “PHP 5 Interpreter”. The php interpreter file generally placed inside the <physical drive in Windows OS>:xamppphpphp.exe

Configure Codeigniter and Netbeans

Create a new PHP project in Netbeans. Then remove the index.php file from the newly created project. Now copy the extracted files from Codeigniter 3.0.6 to the newly created project directory.

Directory Structure

A typical directory structure for the project would be as shown below. Here assests directory will contain static resources like css, js, images.

nested categories codeigniter

Step 1. Now modify <root directory>/application/config/autoload.php file for auto-loading html, url, file, form and session

Add encryption key in ci3/application/config/config.php file

Create ci3/application/libraries/site_config.php file with the following source code

Create ci3/application/hooks/Track_Visitor.php file with the following source code

Modify file ci3/application/config/hooks.php to add the following

Step 2. Go to location ci3/application/config/database.php file and change database parameter values for below parameters

Step 3. Create a MySQL table in “roytuts” database

Step 4. Dump some data into database table – site_log

Step 5. Create a model file visitormodel.php under ci3/application/models directory with the below source code

Step 6. Create a controller file visitorcontroller.php under ci3/application/controllers with the following source code

Step 7. Create a view file visitor.php under ci3/application/views

Step 8. Modify file ci3/application/config/routes.php file

Step 9. Download assets directory.

assets

Step 10. If everything is fine then run the application. You will get the output in the browser.

codeigniter visitor tracking system

Thanks for reading.

6 Replies to “Codeigniter Online Visitor Tracking System”

  1. Hello Soumitra,

    I am getting Unable to load the requested class: Page_hit_counter error so can you please give me this file Page_hit_counter.php.

  2. Hi!
    Good job. however, I noticed that the names of database columns do not correspond to the names of the class Track_Visitor. For example request_uri and requested_url. Similarly with visitormodel (visits_count and no_of_visits).
    I also had a problem with functions siteconfig-> get_db_table_prefix () and siteconfig-> track_visitor ().
    After taking the necessary amendments graph works, but only for the current day. Do you foresee update your code?
    Regards

    1. How did you do to resolve the issue with functions siteconfig-> get_db_table_prefix () and siteconfig-> track_visitor () ?

      Regards

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.