Skip to content

PHP library to save info about visitors of web page into DB.

License

Notifications You must be signed in to change notification settings

xsuchy09/visitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Visitor

PHP library to save info about visitors of web page into DB. PHP 7.1 is required.

Authors:

Overview

Visitor saves info about visitor of web page into db and uses cookie to identify same visitor. Lifetime of that cookie is configurable - default is 10 years. It is using UtmCookie to save UTMs too and Hashids to get unique hash for every single visitor (for example in JavaScript it is not safe to use directly ID from DB).

SQL to create DB table is included (visitor.sql - for PostgreSQL). Column "visits_count" is counted with trigger (new visit is counted if it is more than 24 hours from last visit). You can change it as you want.

Installation (via composer)

Get composer and add this in your requires section of the composer.json:

{
    "require": {
        "xsuchy09/visitor": "*"
    }
}

and then

composer install

Usage

Basic Example

$pdo = $PDO = new PDO(sprintf('pgsql:host=%s;port=%d;dbname=%s;user=%s;password=%s', 'localhost', 5432, 'db_name', 'username', 'password'));
$visitor = new Visitor($pdo, 'HashidsKey'); // it needs pdo instance in constructor and key for Hashids (use your own for your security). You can use others optionally params as you need.
$visitor->addVisit(); // set last visit of of visitor if he is identified or just create the new one with first visit

More examples can be found in the examples/ directory. Since version 1.0.4 you can set cookie params in constructor (path, domain, secure, httpOnly, sameSite) and some getters were added.

About

PHP library to save info about visitors of web page into DB.

Resources

License

Stars

Watchers

Forks

Packages

No packages published