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


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.


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.

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

8 Thoughts on “Codeigniter Online Visitor Tracking System”

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.