PHP: Simple multi-purpose user-tracker

      No Comments on PHP: Simple multi-purpose user-tracker

Introduction

A while ago I needed something that could track visitors and some basic information. I wrote this simple user-tracker that stores the IP, Host-name, Browser-agent, date of last visit and visitor count into a MySQL database table. This piece of code relies on my own database class which you can find here, however you’re free to alter this code to fit your own database. I’m giving away this code for free in the hopes it may be useful to someone but remember, GNU General Public license version 3 applies. See the header of the code for more information.

Usage

You can use this code to determine how many visitors visit a certain page or website on your web-server, determine if a recorded visit was of human or crawler / spider origin and how many times an entity has accessed a page. You are free to modify this code to fit your own purpose. Before you use this code be sure to create the required MySQL database table. I’ve provided MySQL table information in the comment section of my code.

The code

Basically the constructor collects some data using the $_server global array and then performs a database query to determine if the data has already been stored. If the query doesn’t return an array the data will be inserted into the table. If the data is already present in the table the date and visitor count will be updated. Then the information in the database will be updated also.

 

Leave a Reply