This script works fine, until more that one ip is in the log file it creates. Then it only will return the correct number of hits if your the last ip in the log. Whats wrong? Why does it do that? I really can figure it out.
//**************************************
//
// Name: PhP IP Client Logger
// Descriptionetect Client IP, save it
// to file(include first time,last time hit
// ) and count client hit.
// By: Kevin Leonardi
//
//This code is copyrighted and has // limited warranties.Please see http://
// // lngWId.8/qx/vb/scripts/ShowCode.htm //for details. //**************************************
//
<!--
/*************************************************************************/
/* Script Name : IP Logger */
/* Description : Detect Client IP, save it to file, and count client hit */
/* Author : Kevin Leonardi */
/* Email: fotx@yahoo.com */
/* */
/* Please Vote Me if you like my script! */
/*************************************************************************/
//-->
<?php
$found = "false";
$filename = "count.inc";
if (file_exists ($filename))
{$fp = fopen($filename,"r+"}
else{$fp = fopen($filename,"w"}
$offset = 0;
while ($row = fgets($fp,4096)) {
$cols = explode(";",$row);
if ($cols[0] == $HTTP_SERVER_VARS["REMOTE_ADDR"]){
$cols[1]++; // increase counter;
$cols[3] = date("M/d/Y_H:i:s" //save hour minute seconds _ month date year
fseek($fp,$offset);
fputs($fp,implode(";",$cols));
$found = "true";
}
$offset = ftell($fp);
}
if ($found=="false"{
$cols = array($HTTP_SERVER_VARS["REMOTE_ADDR"],1,date("M/d/Y_H:i:s",date("M/d/Y_H:i:s","\n"
fputs($fp,implode(";",$cols));
}
fclose($fp);
?>
<!--
/**************************************************************************/
/*
/* If you'd like this below messages disappear, just remark them with "//"
/* at the every beginning of the line.
/*************************************************************************/
//-->
<HTML>
<HEAD><TITLE>IP Logger</TITLE></HEAD>
<BODY BGCOLOR="#000000">
<font face="Courier,Verdana,Arial" size=3 Color="#FFFFFF">
<b>YOUR IP ADDRESS : <font color="red"><?php echo $HTTP_SERVER_VARS["REMOTE_ADDR"]."<br>"; ?></b></font>
You've been hit this site <font color="red"><b><?php echo $cols[1];?></b></font> times
since <font color="cyan"><b><?php echo eregi_replace("_"," at ",$cols[2]);?>.<br></b></font>
Last time I saw you : <font color="Yellow"><b><?php echo eregi_replace("_"," at ",$cols[3]);?></b></font>.
<br><br>
<font color="lime"><b>Vote Me! if you like this code.</b></font>
<font>
</BODY>
</HTML>
//**************************************
//
// Name: PhP IP Client Logger
// Descriptionetect Client IP, save it
// to file(include first time,last time hit
// ) and count client hit.
// By: Kevin Leonardi
//
//This code is copyrighted and has // limited warranties.Please see http://
// // lngWId.8/qx/vb/scripts/ShowCode.htm //for details. //**************************************
//
<!--
/*************************************************************************/
/* Script Name : IP Logger */
/* Description : Detect Client IP, save it to file, and count client hit */
/* Author : Kevin Leonardi */
/* Email: fotx@yahoo.com */
/* */
/* Please Vote Me if you like my script! */
/*************************************************************************/
//-->
<?php
$found = "false";
$filename = "count.inc";
if (file_exists ($filename))
{$fp = fopen($filename,"r+"}
else{$fp = fopen($filename,"w"}
$offset = 0;
while ($row = fgets($fp,4096)) {
$cols = explode(";",$row);
if ($cols[0] == $HTTP_SERVER_VARS["REMOTE_ADDR"]){
$cols[1]++; // increase counter;
$cols[3] = date("M/d/Y_H:i:s" //save hour minute seconds _ month date year
fseek($fp,$offset);
fputs($fp,implode(";",$cols));
$found = "true";
}
$offset = ftell($fp);
}
if ($found=="false"{
$cols = array($HTTP_SERVER_VARS["REMOTE_ADDR"],1,date("M/d/Y_H:i:s",date("M/d/Y_H:i:s","\n"
fputs($fp,implode(";",$cols));
}
fclose($fp);
?>
<!--
/**************************************************************************/
/*
/* If you'd like this below messages disappear, just remark them with "//"
/* at the every beginning of the line.
/*************************************************************************/
//-->
<HTML>
<HEAD><TITLE>IP Logger</TITLE></HEAD>
<BODY BGCOLOR="#000000">
<font face="Courier,Verdana,Arial" size=3 Color="#FFFFFF">
<b>YOUR IP ADDRESS : <font color="red"><?php echo $HTTP_SERVER_VARS["REMOTE_ADDR"]."<br>"; ?></b></font>
You've been hit this site <font color="red"><b><?php echo $cols[1];?></b></font> times
since <font color="cyan"><b><?php echo eregi_replace("_"," at ",$cols[2]);?>.<br></b></font>
Last time I saw you : <font color="Yellow"><b><?php echo eregi_replace("_"," at ",$cols[3]);?></b></font>.
<br><br>
<font color="lime"><b>Vote Me! if you like this code.</b></font>
<font>
</BODY>
</HTML>