Script Mini-Traffic Site

from: coursesweb.net

This is a PHP script for counting and displaying simple data of web site traffic. Records and displays site visits, unique visitors in the current and previous day, and number of online visitors in the last 60 seconds; as well as the top visits, visitors and record of online visitors, also, the IP of the current visitor.

A demo of this script it is on this page -> PHP Script Mini-Traffic Site

The script is created with PHP. The traffic data can be saved in a text file on the server, or into a MySQL database (using PDO).
This script not records the accesses of bots engines (Googlebot, alexa, crawler, Gigabot, msn, ..., and others, total of 170 bots), and it can be included in both .php and .html files (but the server must run PHP).
• By default, the script is set to save data in text file, in the "minitrafic.txt" file (in the "minitraff/" folder).

Installation

- Copy the "minitrafic.php" file, and the "minitraff" directory on the server, in the same folder where you have the file in which you want to include this script.

1. If you want to save traffic data in text file (in the "minitrafic.txt" file), give write permissions to "minitrafic.txt" (CHMOD 0777, or CHMOD 0755); because the PHP must have write permissions in the "minitrafic.txt" file.

2. If you want to save traffic data in MySQL database:
a) Open the "minitrafic.php" file, and change the 'file' value of the variable $savein to 'mysql' (at line 3), to be like this:
$savein = 'mysql';
b) Add your data for connecting to MySQL database, in these lines of code (in "minitrafic.php"):
protected $hostdb = 'localhost';
protected $namedb = 'database_name';
protected $userdb = 'user_name';
protected $passdb = 'password';
c) Then access the "minitrafic.php" in your browser, with traffic=createtable in URL address, to create the table in MySQL database.
For example, access:   http://domain.com/minitrafic.php?traffic=createtable

1. If you include the script into a .php file, add this code at the beginning of that php file:
include('minitrafic.php');
- Then, in the place where you want to display the traffic data, add this php code:
<?php
echo $html_trafic;
?>
2. If you want to include the script into a .html file, add this code in that HTML, in the place where the traffic data will be displayed:
<script type="text/javascript" src="minitrafic.php?add=minitrafic"></script>
3. In the <head> zone of the HTML document add this CSS styles (or into a external .css file). In this code you can add / edit CSS properties to style the HTML code with traffic data:
<style type="text/css">
#traff{
 position:relative;
 width:13em;
 margin-top:1em;
 background-color:#edeffe;
 border:2px solid #f8feff;
 text-align:left;
 padding:.15em .15em .15em .4em;
 box-shadow:.2em .22em .24em #a0a0ed;
 -webkit-box-shadow:.2em .22em .24em #a0a0ed;
 -moz-border-radius:.8em;
 -webkit-border-radius:.8em;
 -khtml-border-radius:.8em;border-radius:.8em;
}
#traff .traf{
 position:relative;
 margin:4px 1px 2px 1px;
 font-weight:800;
 text-align:center;
}
#traff .traf sup, #f_sub sup{
 font-weight:normal;
 font-style:italic;
}
#traff .su { text-decoration: underline; }
#traff #dtnow { color:blue; }
</style>
The files "test.php" and "test.html" are for test, to see how to include this script in .php and .html file.

It was succesfully tested on localhost (with XAMPP), and on the websites: http://coursesweb.net and www.marplo.net , with Mozilla Firefox, Internet Explorer, Google Chrome, and Opera.

- This script is Free, without assistance, you can use it and modify how you want.


Have Good Life,
Marius