Simple Daily Visitor Counter. php scripts.

  • Benny

Benny

grand_3
07 Dec 2022

  • ratio potencial important = 0% (of 100)
    skor star1star1star1star1star1(auto skor by people)
  • 1 0 respond: 1
    sbRespond: 0
    1 1
    peserta

Simple Daily Visitor Counter. php scripts.

Define by time = Date DMY

 

1. Connect database sql.

file name lib.php

<?php

	$dbhost = "localhost"; // server
	$dbuser = "root"; // user
	$dbpass = "pwd123"; // password

	$dbname = "db";

	$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

 

2. Bot or Human.

detection by useragent, place under connection scripts file lib.php

$u_agent = @$_SERVER['HTTP_USER_AGENT'];
if(!$u_agent){$u_agent="undefinition";}

function get_os_name($u_agent)
{
global $u_agent;
$ostypes = array(
"Windows" => "(Win16)|(Windows)|(Win95)|(Win 9x 4.90)|(Win98)|(WinNT)",
"SunOS" => "SunOS",
"Phone" => "(Android)|(iPhone)|(iPad)",
"Linux" => "(Linux)|(X11)|(Ubuntu)|(OpenBSD)",
"MacOS" => "(Mac_PowerPC)|(Macintosh)",
"QNX" => "QNX",
"BeOS" => "BeOS",
"OS2" => "OS/2",
"SearchBot" => "(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)"
);
$u_agent = strtolower($u_agent ? $u_agent : $_SERVER['HTTP_USER_AGENT']);
foreach ($ostypes as $os => $pattern)
if (preg_match("/" . @$pattern . "/i", @$u_agent))
return @$os;
return "undefinition";
}
$_MACHINE = get_os_name($u_agent);

$humy=array("Windows","Linux","MacOS","SunOS","Phone","QNX","BeOS","OS2");
$human=in_array($_MACHINE, $humy);

?>

 

3. Create New Table SQL/ phpMyadmin, =day_visitor_count=

CREATE TABLE `day_visitor_count` (
  `ID` bigint(1) NOT NULL,
  `addr` varchar(250) NOT NULL,
  `day` varchar(250) DEFAULT "1",
  `counts` varchar(250) NOT NULL,
  `humn` varchar(70) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT "1",
  `refr` varchar(250) DEFAULT "0",
  `uagn` varchar(250) NOT NULL,
  `dater` varchar(70) DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

 

4. Scripts to Analisis Visitor.

File Name =d_count.php= place in header, foother Page, like include ("d_count.php");  .

<?php

	$t = time();
	$today_Day = date("D M Y", $t);

	//[1]Update database
	$sql_Tdb = "SELECT `day` FROM `day_visitor_count` WHERE `day`='{$today_Day}' ORDER BY CAST(`dater` AS UNSIGNED) DESC limit 1 ";
	$query_Tdb = mysqli_query($conn, $sql_Tdb );

	$nr_Tdb = mysqli_num_rows($query_Tdb );

	if($nr_Tdb){
	$sql_up_stat = "UPDATE `day_visitor_count` set `counts`=`counts`+1 WHERE `day`='{$today_Day}' ";
	$query_up_stat = mysqli_query($conn, $sql_up_stat );
	}else{
	if($human){$val_hum="1";}else{$val_hum="0";}
  
	$sql_statUP = "INSERT INTO `day_visitor_count`(`ID`, `addr`, `day`, `counts`, `humn`, `refr`, `uagn`, `dater`) VALUES (NULL, '{$addr}', '{$today_Day}', '1', '{$val_hum}', '{$referr}', '{$u_agent}', '{$t}')";
	$q_statUP = mysqli_query($conn, $sql_statUP );
	}



	//[2]Call Result
	$sqView = "select sum(counts) as jmlview from `day_visitor_count` ";
	$qView = mysqli_query($conn, $sqView);

	$rView = @mysqli_fetch_array($qView, MYSQLI_ASSOC);
	$viewAll = $rView['jmlview'];

	if(!$viewAll){$viewAll=1;}


	//day
	$sq_vDay = "SELECT * FROM `day_visitor_count` ";
	$q_vDay = mysqli_query($conn, $sq_vDay);
	$nr_vDay = mysqli_num_rows($q_vDay);

	if(!$nr_vDay){$nr_vDay=1;}

	$avg_b9 = $viewAll/$nr_vDay;

	$DAY_STAT_VIEW_AVG = number_format($avg_b9, '0'); //display result query



	//clean table efery 30days. 90 for 90days, ,..
	if($nr_vDay>=30){

	$sq_drpStat = "DELETE FROM `day_visitor_count`";
	$q_drpStat = mysqli_query($conn, $sq_drpStat);

	$sq_statUPNw = "INSERT INTO `day_visitor_count`(`ID`, `addr`, `day`, `counts`, `refr`, `uagn`, `dater`) VALUES (NULL, '{$addr}', '{$today_Day}', '1', '{$referr}', '{$u_agent}', '{$t}')";
	$q_statUPNw = mysqli_query($conn, $sq_statUPNw);

	}


?>

 

 

Demo benny9.my.id bootom/ footer

Benny

grand_3
  • 0 0
LIKE 

Simple Daily Visitor Counter. php scripts.

Define by time = Date DMY

 

1. Connect database sql.

file name lib.php

<?php

	$dbhost = "localhost"; // server
	$dbuser = "root"; // user
	$dbpass = "pwd123"; // password

	$dbname = "db";

	$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

 

2. Bot or Human.

detection by useragent, place under connection scripts file lib.php

$u_agent = @$_SERVER['HTTP_USER_AGENT'];
if(!$u_agent){$u_agent="undefinition";}

function get_os_name($u_agent)
{
global $u_agent;
$ostypes = array(
"Windows" => "(Win16)|(Windows)|(Win95)|(Win 9x 4.90)|(Win98)|(WinNT)",
"SunOS" => "SunOS",
"Phone" => "(Android)|(iPhone)|(iPad)",
"Linux" => "(Linux)|(X11)|(Ubuntu)|(OpenBSD)",
"MacOS" => "(Mac_PowerPC)|(Macintosh)",
"QNX" => "QNX",
"BeOS" => "BeOS",
"OS2" => "OS/2",
"SearchBot" => "(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)"
);
$u_agent = strtolower($u_agent ? $u_agent : $_SERVER['HTTP_USER_AGENT']);
foreach ($ostypes as $os => $pattern)
if (preg_match("/" . @$pattern . "/i", @$u_agent))
return @$os;
return "undefinition";
}
$_MACHINE = get_os_name($u_agent);

$humy=array("Windows","Linux","MacOS","SunOS","Phone","QNX","BeOS","OS2");
$human=in_array($_MACHINE, $humy);

?>

 

3. Create New Table SQL/ phpMyadmin, =day_visitor_count=

CREATE TABLE `day_visitor_count` (
  `ID` bigint(1) NOT NULL,
  `addr` varchar(250) NOT NULL,
  `day` varchar(250) DEFAULT "1",
  `counts` varchar(250) NOT NULL,
  `humn` varchar(70) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT "1",
  `refr` varchar(250) DEFAULT "0",
  `uagn` varchar(250) NOT NULL,
  `dater` varchar(70) DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

 

4. Scripts to Analisis Visitor.

File Name =d_count.php= place in header, foother Page, like include ("d_count.php");  .

<?php

	$t = time();
	$today_Day = date("D M Y", $t);

	//[1]Update database
	$sql_Tdb = "SELECT `day` FROM `day_visitor_count` WHERE `day`='{$today_Day}' ORDER BY CAST(`dater` AS UNSIGNED) DESC limit 1 ";
	$query_Tdb = mysqli_query($conn, $sql_Tdb );

	$nr_Tdb = mysqli_num_rows($query_Tdb );

	if($nr_Tdb){
	$sql_up_stat = "UPDATE `day_visitor_count` set `counts`=`counts`+1 WHERE `day`='{$today_Day}' ";
	$query_up_stat = mysqli_query($conn, $sql_up_stat );
	}else{
	if($human){$val_hum="1";}else{$val_hum="0";}
  
	$sql_statUP = "INSERT INTO `day_visitor_count`(`ID`, `addr`, `day`, `counts`, `humn`, `refr`, `uagn`, `dater`) VALUES (NULL, '{$addr}', '{$today_Day}', '1', '{$val_hum}', '{$referr}', '{$u_agent}', '{$t}')";
	$q_statUP = mysqli_query($conn, $sql_statUP );
	}



	//[2]Call Result
	$sqView = "select sum(counts) as jmlview from `day_visitor_count` ";
	$qView = mysqli_query($conn, $sqView);

	$rView = @mysqli_fetch_array($qView, MYSQLI_ASSOC);
	$viewAll = $rView['jmlview'];

	if(!$viewAll){$viewAll=1;}


	//day
	$sq_vDay = "SELECT * FROM `day_visitor_count` ";
	$q_vDay = mysqli_query($conn, $sq_vDay);
	$nr_vDay = mysqli_num_rows($q_vDay);

	if(!$nr_vDay){$nr_vDay=1;}

	$avg_b9 = $viewAll/$nr_vDay;

	$DAY_STAT_VIEW_AVG = number_format($avg_b9, '0'); //display result query



	//clean table efery 30days. 90 for 90days, ,..
	if($nr_vDay>=30){

	$sq_drpStat = "DELETE FROM `day_visitor_count`";
	$q_drpStat = mysqli_query($conn, $sq_drpStat);

	$sq_statUPNw = "INSERT INTO `day_visitor_count`(`ID`, `addr`, `day`, `counts`, `refr`, `uagn`, `dater`) VALUES (NULL, '{$addr}', '{$today_Day}', '1', '{$referr}', '{$u_agent}', '{$t}')";
	$q_statUPNw = mysqli_query($conn, $sq_statUPNw);

	}


?>

 

 

Demo benny9.my.id bootom/ footer

Wait,..
Refferer?
$referr = @$_SERVER["HTTP_REFERER"];
if(!$referr){ $referr =""; }

no bot
}elseif($human){

//clean table efery 30days, 60day, 90days, 360days (1year) Low Rows Db. no saving IP.

 

Download Scripts : https://pc.benny9.my.id/file/ -> file stat-scripts.rar

 


translator
English
Chinese