Log Your Visitor

Log Your Visitor
Email This Post  Print This Post

Traffic Log

Traffic Log

Because there is many of my blog visitor asking about “Traffic Log” widget on my sidebar, so it will be easier to publish the code instead of have to tell them again and again. But first thing you should know that this is not my code. I get this from one of best friend in internet world, Hadoitz. I have his approvement to publish this code to you all. It’s Open Source, so you can freely edit the code. What I’m going to tell you here, is what I’m doing for my blog. You can recoded however you like based on your web configuration.

First rule, you must have an access to your web database (phpmyadmin). For example, if your web hosted in blogspot.com (eg. http://yourwebname.blogspot.com) or wordpress.com (eg. http://yourwebname.wordpress.com), you don’t have an access to your web database. In my case, I use wordpress engine that can be download from http://wordpress.org and host it to a free web hoster, http://0fees.net.

Second step, access to your web database and make new table “wp_traffic” with 4 column :

  • id : int(100), auto_increment, primary key
  • ip : varchar(100)
  • referer : varchar(100)
  • waktu : varchar(100)

Then, put this code wherever you like on your web

<h2>Traffic Log</h2>
<?php
$waktu = date("d/n/y - H:i:s");
$count = mysql_num_rows(mysql_query("SELECT * FROM wp_traffic"));
$hariIni = date("j/n/Y");

$ip = $_SERVER['REMOTE_ADDR'];

if
  ( mysql_num_rows
    ( mysql_query
      ( "SELECT * FROM wp_traffic WHERE ip = '$_SERVER[REMOTE_ADDR]'")) == 0
      and $_GET["admin"] != "true"
      and !eregi("admin", $_SERVER["HTTP_REFERER"])
  )
{ if (!eregi("http://www.maisbiz.0fees.net", $_SERVER["HTTP_REFERER"]))
  {
    mysql_query
    ( "INSERT INTO wp_traffic (ip, referer, waktu) VALUES ('$_SERVER[REMOTE_ADDR]',
      '$_SERVER[HTTP_REFERER]', '$waktu')") or die(mysql_error());
  }
  else
  {
    mysql_query
    ( "INSERT INTO wp_traffic (ip, referer, waktu) VALUES ('$_SERVER[REMOTE_ADDR]',
      '', '$waktu')") or die(mysql_error());
  }
}

$qTraffic = mysql_query
  ( "SELECT * FROM wp_traffic ORDER BY id DESC LIMIT 0,7") or die(mysql_error());

while ($aTraffic = mysql_fetch_array($qTraffic))
{
  if ($aTraffic["referer"] != "")
  {
    $referer = parse_url($aTraffic["referer"], PHP_URL_HOST);
    echo "
      <li><font color=#307f95><b>$aTraffic[ip]</b></font><br />
      from $referer<br />
      on $aTraffic[waktu]</li>
      ";
  }
  else
  {
    echo "
      <li><font color=#307f95><b>$aTraffic[ip]</b></font><br />
      on $aTraffic[waktu]</li>
      ";
  }

}
echo "<i>Traffic Log Credits : Hadoitz</i>";
?>

Note : Learn the code, then recoded based on your web configuration.