Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whats going on?

Status
Not open for further replies.

f117bomb

MIS
Nov 24, 2001
13
US
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
// Description:Detect 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 = &quot;false&quot;;
$filename = &quot;count.inc&quot;;
if (file_exists ($filename))
{$fp = fopen($filename,&quot;r+&quot;);}
else{$fp = fopen($filename,&quot;w&quot;);}
$offset = 0;
while ($row = fgets($fp,4096)) {
$cols = explode(&quot;;&quot;,$row);
if ($cols[0] == $HTTP_SERVER_VARS[&quot;REMOTE_ADDR&quot;]){
$cols[1]++; // increase counter;
$cols[3] = date(&quot;M/d/Y_H:i:s&quot;); //save hour minute seconds _ month date year
fseek($fp,$offset);
fputs($fp,implode(&quot;;&quot;,$cols));
$found = &quot;true&quot;;
}
$offset = ftell($fp);
}
if ($found==&quot;false&quot;){
$cols = array($HTTP_SERVER_VARS[&quot;REMOTE_ADDR&quot;],1,date(&quot;M/d/Y_H:i:s&quot;),date(&quot;M/d/Y_H:i:s&quot;),&quot;\n&quot;);
fputs($fp,implode(&quot;;&quot;,$cols));
}
fclose($fp);
?>
<!--
/**************************************************************************/
/*
/* If you'd like this below messages disappear, just remark them with &quot;//&quot;
/* at the every beginning of the line.
/*************************************************************************/
//-->
<HTML>
<HEAD><TITLE>IP Logger</TITLE></HEAD>
<BODY BGCOLOR=&quot;#000000&quot;>
<font face=&quot;Courier,Verdana,Arial&quot; size=3 Color=&quot;#FFFFFF&quot;>
<b>YOUR IP ADDRESS : <font color=&quot;red&quot;><?php echo $HTTP_SERVER_VARS[&quot;REMOTE_ADDR&quot;].&quot;<br>&quot;; ?></b></font>
You've been hit this site <font color=&quot;red&quot;><b><?php echo $cols[1];?></b></font> times
since <font color=&quot;cyan&quot;><b><?php echo eregi_replace(&quot;_&quot;,&quot; at &quot;,$cols[2]);?>.<br></b></font>
Last time I saw you : <font color=&quot;Yellow&quot;><b><?php echo eregi_replace(&quot;_&quot;,&quot; at &quot;,$cols[3]);?></b></font>.
<br><br>
<font color=&quot;lime&quot;><b>Vote Me! if you like this code.</b></font>
<font>
</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top