kali ini saya mau sharing tentang Cara Membuat Statistik Website Sendiri, yang fungsinya adalah agar yg punya website dan pengunjung website tau berapa banyak yang mengunjungi website yg kita miliki. pada statistik pengunjung
ini akan menampilkan informasi berapa banyak pengunjung website pada
hari ini, berapa banyak pengunjung website kemain, bulan ini, tahun ini
dan total seluruh pengunjung. dan terdapat informasi Hits Count yaitu
informasi tentang berapa kali halaman pada website kita di buka oleh
pengunjung, atau di refresh oleh pengunjung. dan ada juga informasi
siapa saja yang sedang online saat ini.
sekian tutorial tentang Cara Membuat Statistik Website Sendiri,, silahkan di coba, semoga sukses
yang
harus di siapkan pertama adalah server website kita, disini saya
gunakan Xampp 1.6, silahkan di aktifkan terlebih dahulu web server anda,
jika sudah buat database baru dengan cara buka web browser dan ketikkan
http://localhost/phpmyadmin , atau temen - temen juga bisa membuatnya
dengan menggunakan software seperti Mysql-Front atau SQLYog. dan masih
banyak lagi. buatlah database dengan nama misal :artikelhitcounter, jika sudah selanjutnya buat tabel konter, hitscounter, dan useronline. dan field - fieldnya bisa liat
##### Script Mysql Di bawah ini ########
CREATE TABLE `hitscounter` (
`hits` varchar(100) collate latin1_general_ci NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
`hits` varchar(100) collate latin1_general_ci NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
INSERT INTO `hitscounter` VALUES ('0');
CREATE TABLE `konter` (
`ip` varchar(50) collate latin1_general_ci NOT NULL default '',
`tanggal` varchar(20) collate latin1_general_ci NOT NULL default '',
`waktu` varchar(20) collate latin1_general_ci NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
`ip` varchar(50) collate latin1_general_ci NOT NULL default '',
`tanggal` varchar(20) collate latin1_general_ci NOT NULL default '',
`waktu` varchar(20) collate latin1_general_ci NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
CREATE TABLE `usersonline` (
`timestamp` varchar(100) collate latin1_general_ci NOT NULL default '',
`ip` varchar(100) collate latin1_general_ci NOT NULL default '',
`file` varchar(100) collate latin1_general_ci NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
`timestamp` varchar(100) collate latin1_general_ci NOT NULL default '',
`ip` varchar(100) collate latin1_general_ci NOT NULL default '',
`file` varchar(100) collate latin1_general_ci NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
jika database dan tabel sudah selesai di buat, di bawah ini script PHPnya.
###### koneksi.php ####
<?
$server = "localhost";
$db_user = "root";
$db_pass = "";
$db = "fr_system";
$koneksi=mysql_connect($server,$db_user,$db_pass);
mysql_select_db($db,$koneksi);
?>
$server = "localhost";
$db_user = "root";
$db_pass = "";
$db = "fr_system";
$koneksi=mysql_connect($server,$db_user,$db_pass);
mysql_select_db($db,$koneksi);
?>
##### useronline.php ######
<?
include "koneksi.php";
$to_secs = 120;
$t_stamp = time();
$timeout = $t_stamp - $to_secs;
$REMOTEADDR=$_SERVER['REMOTE_ADDR'];
$PHPSELF=$_SERVER['PHP_SELF'];
mysql_connect($server, $db_user, $db_pass) or die ("Useronline Database CONNECT Error");
mysql_db_query($db, "INSERT INTO usersonline VALUES ('$t_stamp','$REMOTEADDR','$PHPSELF')") or die("Database INSERT Error");
mysql_db_query($db, "DELETE FROM usersonline WHERE timestamp<$timeout") or die("Database DELETE Error");
$result = mysql_db_query($db, "SELECT DISTINCT ip FROM usersonline WHERE file='$PHPSELF'") or die("Database SELECT Error");
$user = mysql_num_rows($result);
mysql_close();
include "koneksi.php";
$to_secs = 120;
$t_stamp = time();
$timeout = $t_stamp - $to_secs;
$REMOTEADDR=$_SERVER['REMOTE_ADDR'];
$PHPSELF=$_SERVER['PHP_SELF'];
mysql_connect($server, $db_user, $db_pass) or die ("Useronline Database CONNECT Error");
mysql_db_query($db, "INSERT INTO usersonline VALUES ('$t_stamp','$REMOTEADDR','$PHPSELF')") or die("Database INSERT Error");
mysql_db_query($db, "DELETE FROM usersonline WHERE timestamp<$timeout") or die("Database DELETE Error");
$result = mysql_db_query($db, "SELECT DISTINCT ip FROM usersonline WHERE file='$PHPSELF'") or die("Database SELECT Error");
$user = mysql_num_rows($result);
mysql_close();
if ($user == 1){
echo "<b>$user</b> User";
}
else{
echo "<b>$user</b> Users";
}
?>
echo "<b>$user</b> User";
}
else{
echo "<b>$user</b> Users";
}
?>
####### counter.php #######
<?
include "koneksi.php";
$countertabel=mysql_query("SELECT * FROM hitscounter");
$totalyangada=mysql_fetch_array($countertabel);
$totalyangada1=$totalyangada[hits]+1;
$updatecounter=mysql_query("UPDATE hitscounter SET hits = '$totalyangada1'");
$tampilkansekarang=mysql_query("SELECT * FROM hitscounter");
$tampilkansekarang1=mysql_fetch_array($tampilkansekarang);
echo "$tampilkansekarang1[hits]";
?>
include "koneksi.php";
$countertabel=mysql_query("SELECT * FROM hitscounter");
$totalyangada=mysql_fetch_array($countertabel);
$totalyangada1=$totalyangada[hits]+1;
$updatecounter=mysql_query("UPDATE hitscounter SET hits = '$totalyangada1'");
$tampilkansekarang=mysql_query("SELECT * FROM hitscounter");
$tampilkansekarang1=mysql_fetch_array($tampilkansekarang);
echo "$tampilkansekarang1[hits]";
?>
###### index.php #########
<?
session_start();
$tip=$_SESSION['ip'];
$tjam=$_SESSION['jam'];
$ttgl=$_SESSION['tgl'];
if($tip=='' && $tjam=='' && $ttgl==''){
$ip=$_SERVER['REMOTE_ADDR'];
$jam=date("h:i:s");
$tgl=date("d-m-Y");
$_SESSION ["ip"] = $ip;
$_SESSION ["jam"] = $jam;
$_SESSION ["tgl"] = $tgl;
}
$sip=$_SESSION['ip'];
$sjam=$_SESSION['jam'];
$stgl=$_SESSION['tgl'];
require "koneksi.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
session_start();
$tip=$_SESSION['ip'];
$tjam=$_SESSION['jam'];
$ttgl=$_SESSION['tgl'];
if($tip=='' && $tjam=='' && $ttgl==''){
$ip=$_SERVER['REMOTE_ADDR'];
$jam=date("h:i:s");
$tgl=date("d-m-Y");
$_SESSION ["ip"] = $ip;
$_SESSION ["jam"] = $jam;
$_SESSION ["tgl"] = $tgl;
}
$sip=$_SESSION['ip'];
$sjam=$_SESSION['jam'];
$stgl=$_SESSION['tgl'];
require "koneksi.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="102" colspan="2" align="center" valign="middle" bgcolor="#99CC00">BANNER</td>
</tr>
<tr>
<td width="206" height="88" align="center" valign="top"><?php
$ip=$_SERVER['REMOTE_ADDR'];
$tanggal=date("d-m-Y");
$tgl=date("d");
$bln=date("m");
$thn=date("Y");
$tglk=$tgl-1;
$baca=mysql_query("SELECT * FROM konter WHERE ip='$sip' AND tanggal='$stgl' AND waktu='$sjam'");
$baca1=mysql_num_rows($baca);
if($baca1==0){
$tkonter=mysql_query("INSERT INTO konter VALUES ('$sip','$stgl','$sjam')");
}
$q=mysql_query("SELECT * FROM konter");
$blan=date("m-Y");
$bulan=mysql_query("SELECT * FROM konter WHERE tanggal LIKE '%$blan%'");
$tahunini=mysql_query("SELECT * FROM konter WHERE tanggal LIKE '%$thn%'");
$today=mysql_query("SELECT * FROM konter WHERE tanggal='$tanggal'");
if($tglk=='1' | $tglk=='2' | $tglk=='3' | $tglk=='4' | $tglk=='5' | $tglk=='6' | $tglk=='7' | $tglk=='8' | $tglk=='9'){
$kemarin=mysql_query("SELECT * FROM konter WHERE tanggal='0$tglk-$bln-$thn'");
} else {
$kemarin=mysql_query("SELECT * FROM konter WHERE tanggal='$tglk-$bln-$thn'");
}
$visitor = mysql_num_rows($q);
$bulan1=mysql_num_rows($bulan);
$tahunini1=mysql_num_rows($tahunini);
$kemarin1 = mysql_num_rows($kemarin);
$todays=mysql_num_rows($today);
?>
<table width="189" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="109"> Online </td>
<td width="80">: <? include "useronline.php"; ?> </td>
</tr>
<tr>
<td> Total Hits</td>
<td>:
<? include "counter.php"; ?>
Hits </td>
</tr>
<tr>
<td>Hari Ini </td>
<td>:
<?=$todays;?></td>
</tr>
<tr>
<td>Kemarin</td>
<td>:
<?=$kemarin1;?></td>
</tr>
<tr>
<td>Bulan Ini</td>
<td> :
<?=$bulan1;?></td>
</tr>
<tr>
<td> Tahun Ini </td>
<td>:
<?=$tahunini1;?></td>
</tr>
<tr>
<td> Total</td>
<td>:
<?=$visitor;?></td>
</tr>
</table> </td>
<td width="594"> </td>
</tr>
<tr>
<td height="25" colspan="2" align="center" valign="middle" bgcolor="#99CC00">Footer</td>
</tr>
</table>
</body>
</html>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="102" colspan="2" align="center" valign="middle" bgcolor="#99CC00">BANNER</td>
</tr>
<tr>
<td width="206" height="88" align="center" valign="top"><?php
$ip=$_SERVER['REMOTE_ADDR'];
$tanggal=date("d-m-Y");
$tgl=date("d");
$bln=date("m");
$thn=date("Y");
$tglk=$tgl-1;
$baca=mysql_query("SELECT * FROM konter WHERE ip='$sip' AND tanggal='$stgl' AND waktu='$sjam'");
$baca1=mysql_num_rows($baca);
if($baca1==0){
$tkonter=mysql_query("INSERT INTO konter VALUES ('$sip','$stgl','$sjam')");
}
$q=mysql_query("SELECT * FROM konter");
$blan=date("m-Y");
$bulan=mysql_query("SELECT * FROM konter WHERE tanggal LIKE '%$blan%'");
$tahunini=mysql_query("SELECT * FROM konter WHERE tanggal LIKE '%$thn%'");
$today=mysql_query("SELECT * FROM konter WHERE tanggal='$tanggal'");
if($tglk=='1' | $tglk=='2' | $tglk=='3' | $tglk=='4' | $tglk=='5' | $tglk=='6' | $tglk=='7' | $tglk=='8' | $tglk=='9'){
$kemarin=mysql_query("SELECT * FROM konter WHERE tanggal='0$tglk-$bln-$thn'");
} else {
$kemarin=mysql_query("SELECT * FROM konter WHERE tanggal='$tglk-$bln-$thn'");
}
$visitor = mysql_num_rows($q);
$bulan1=mysql_num_rows($bulan);
$tahunini1=mysql_num_rows($tahunini);
$kemarin1 = mysql_num_rows($kemarin);
$todays=mysql_num_rows($today);
?>
<table width="189" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="109"> Online </td>
<td width="80">: <? include "useronline.php"; ?> </td>
</tr>
<tr>
<td> Total Hits</td>
<td>:
<? include "counter.php"; ?>
Hits </td>
</tr>
<tr>
<td>Hari Ini </td>
<td>:
<?=$todays;?></td>
</tr>
<tr>
<td>Kemarin</td>
<td>:
<?=$kemarin1;?></td>
</tr>
<tr>
<td>Bulan Ini</td>
<td> :
<?=$bulan1;?></td>
</tr>
<tr>
<td> Tahun Ini </td>
<td>:
<?=$tahunini1;?></td>
</tr>
<tr>
<td> Total</td>
<td>:
<?=$visitor;?></td>
</tr>
</table> </td>
<td width="594"> </td>
</tr>
<tr>
<td height="25" colspan="2" align="center" valign="middle" bgcolor="#99CC00">Footer</td>
</tr>
</table>
</body>
</html>
dan setelah di jalankan maka hasilnya seperti gambar di bawah ini :
sekian tutorial tentang Cara Membuat Statistik Website Sendiri,, silahkan di coba, semoga sukses