dev-master
9999999-dev https://github.com/dykyi-romanOnline visitors counter
MIT
The Requires
- php >=5.6
- predis/predis ^1.1
The Development Requires
by Dykyi Roman
online visitors
Wallogit.com
2017 © Pedro Peláez
Online visitors counter
1) First we need a MySQL table to store our information, (*1)
CREATE TABLE online_visitors(
session_id CHAR(100) NOT NULL DEFAULT '',
time INT(11) NOT NULL DEFAULT '0'
);
or use Redis., (*2)
2) We are checking if the session has been already started, if it's not, then start the session, (*3)
3) We created two variables, one is the current time and the other contains the current time minus n minutes, (*4)
4) We need to check the session_id is already stored or not, so we query the database and see if it doesn't exist, then we'll store it and if it does exist, we will update the session's time in the DB, (*5)
5) We get the count of the total session, (*6)
6) We then check if the session has been in the database for more than 10 minutes, if it is, then we will delete it., (*7)
The preferred way to install this extension is through Composer., (*8)
Either run, (*9)
composer require dykyi-roman/online-visitors-counter "dev-master"
or add, (*10)
"dykyi-roman/online-visitors-counter": "master"
to the require section of your composer.json, (*11)
use Dykyi\Driver\MySQLDB; use Dykyi\DBFactory; use Dykyi\VisitorsCounter; $dbFactory = new DBFactory(); $dbFactory->setDriver(MySQLDB::class); $dataBase = $dbFactory->makeDB(['127.0.0.1','homestead','homestead','secret']); $repository = $dbFactory->getRepository($dataBase); echo VisitorsCounter::getCount($repository);
Dykyi Roman, e-mail: mr.dukuy@gmail.com, (*12)
Online visitors counter
MIT
online visitors