Plugin Name: wp-infos
Version: 0.3
Plugin URI: https://sebacatalano.altervista.org
Description: Show the total visits, the current ip and browser of the user.
Author: Seba Catalano
Author URI: https://sebacatalano.altervista.org
Not too many ways on his site to contact him
plug in file
<?php
/*
Plugin Name: wp-infos
Version: 0.3
Plugin URI: https://sebacatalano.altervista.org
Description: Show the total visits, the current ip and browser of the user.
Author: Seba Catalano
Author URI: https://sebacatalano.altervista.org
*/
function wp_infos() {
$timeout = "5"; // Timeout, in minutes, to consider a visitor online.
$ip = $_SERVER['REMOTE_ADDR']; // Ip of the visitor
$browser = $_SERVER['HTTP_USER_AGENT']; // Browser of the visitor
$host = $_SERVER['SERVER_NAME']; // Local host name.
$referer = $_SERVER['HTTP_REFERER']; // Ref url
// Database extraction
$query = mysql_query("SELECT * FROM wp_infos WHERE visits != '0'")
or die("Error in query: ". mysql_error());
$dbarray = mysql_fetch_array($query);
$id = $dbarray['id'];
$totalcount = $dbarray['visits'];
$partialcount = $dbarray['daycount'];
$date = $dbarray['daydate'];
$online = usr_online($timeout, $ip);
counter($id, $totalcount, $partialcount, $host, $date, $referer);
// Visualitazion table
echo "Total visits: $totalcount<br>
Today visits: $partialcount<br>
Users online: $online<br>
Your ip: $ip<br>
Your browser: $browser<br>";
}
function usr_online ($timeout, $ip) {
$time = time();
$less = $time - ($timeout*60);
mysql_query("INSERT INTO wp_infos (ip, time) VALUES ('$ip', '$time')") or die("Error in query: ". mysql_error());
mysql_query("DELETE FROM wp_infos WHERE time<'$less' AND visits=0") or die("Error in query: ". mysql_error());
$query = mysql_query("SELECT COUNT(DISTINCT ip) FROM wp_infos") or die("Error in query: ". mysql_error());
$iplist = mysql_fetch_array($query, MYSQL_NUM);
return $iplist[0]-1;
}
function counter ($id, $totalcount, $partialcount, $host, $date, $referer) {
// Date
$time = getdate();
// Vars initialization
if (empty($id)) {$id = 0;}
if (empty($totalcount)) {$totalcount = 0;}
if (empty($partialcount)) {$partialcount = 0;}
if (empty($date)) {$date = $time[mday].$time[month];}
if (!eregi($host, $referer)) {
$totalcount++;
if (!strcmp($date, $time[mday].$time[month])) {
$partialcount++;
}
else {
$partialcount = 0;
$date = $time[mday].$time[month];
}
// Database entry
mysql_query("DELETE FROM wp_infos WHERE visits!=0")
or die("Error in query: ". mysql_error());
mysql_query("INSERT INTO wp_infos (visits, daycount, daydate) VALUES ($totalcount, $partialcount, '$date')")
or die("Error in query: ". mysql_error());
}
}
?>
Any suggestions most welcome