CREATE TABLE IF NOT EXISTS `counter` (
`id` int(250) NOT NULL AUTO_INCREMENT,
`location` varchar(250) NOT NULL,
`ip` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2273 ;
<?php
include "koneksi.php";
function initCounter() {
$ip = $_SERVER['REMOTE_ADDR']; // menangkap ip pengunjung
$location = $_SERVER['PHP_SELF']; // menangkap server path
//membuat log dalam tabel database 'counter'
$create_log = mysql_query("INSERT INTO counter(ip,location)VALUES('$ip', '$location') ");}
function getCounter($mode, $location = NULL) {
if(is_null($location)) {
$location = $_SERVER['PHP_SELF'];}
if($mode == "unique") {
$get_res = mysql_query("SELECT DISTINCT ip FROM counter1 WHERE location = '$location' ");
} else{
$get_res = mysql_query("SELECT ip FROM counter1 WHERE location = '$location' ");
}
$res = mysql_num_rows($get_res);
return $res;
}
?>
untuk menampilkan atau panggil ip yang tersimpan masukan coding kedalam file index.php
<?php
include_once("counter.php");
initCounter();
echo " ".getCounter('hits')." | ".getCounter('unique')."";
?>
0 Comments